[FRPythoneers] dir()

Jeffery D. Collins jcollins at boulder.net
Fri Feb 15 20:14:33 MST 2002


I recall a similar question posted a few weeks ago.  Here is a link to 
that thread:

http://groups.google.com/groups?hl=en&threadm=mailman.1012618323.27059.python-list%40python.org&rnum=5&prev=/groups%3Fq%3Dpython%2Bdir%2Bchange%26hl%3Den%26selm%3Dmailman.1012618323.27059.python-list%2540python.org%26rnum%3D5


Eric Brunson wrote:

> I've hit a stumbling block porting some of my code from 1.5 to 2.2.
> 
> In pre 2.2 versions dir() would return only the attributes of my
> object that I created.  Now that all primitives are objects I also get
> a couple of extra attributes ('__doc__' and '__module__') and all my
> method names also.
> 
> Maybe the old behaviour was to return the method names, too, but it
> suppressed the __*__ names, which were the only methods this object
> had.
> 
> Is there a preferred way to get only the list of the non-method
> attributes?
> 
> Here's an example of what I'm talking about:
> 
> s0125(~)$ cat > test.py
> class thing:
>     def __init__( self ):
>         self.one = 1
>         self.two = 2
> 
> my = thing()
> print dir( my )
> 
> s0125(~)$ python1.5 test.py
> ['one', 'two']
> 
> s0125(~)$ python2.2 test.py
> ['__doc__', '__init__', '__module__', 'one', 'two']
> 
> 
> For the time being I can examine the attribute name for the '__' since
> the only method the actual class has is __repr__, but I'd rather have
> a more reliable way to do what I'm looking for.
> 
> Thanks,
> e.
> 
> 



-- 
Jeffery Collins (http://www.boulder.net/~jcollins)




More information about the FRPythoneers mailing list