Confused by List behavior

Michael Hudson mwh21 at
Thu Apr 20 14:04:05 CEST 2000

ejbaker_seekonk at writes:

> As a python newbie, I entered this script to explore list processing
> behaviours.
> yy = dir()
> for element in yy:
>   print element
> for element in yy:
>   print dir(element)
> The first 'for' loop works as expected. It returns,
> ['__builtins__', '__doc__', '__name__'].
> The second loop, however, returns three empty lists. For the life of
> me, I can't understand that. Becauese, if I type 'dir(__builtins__)',
> in a script, I get all of the elements of __builtins__.

dir("__builtins__") != dir(__builtins__).

Maybe you want "getattr"?  Eg.

for element in dir(ob):
    print dir(getattr(ob,element))


  On the other hand,  the following areas are subject to boycott
  in reaction to the rampant impurity of design or execution, as
  determined after a period of study, in no particular order: 

More information about the Python-list mailing list