[FRPythoneers] dir()

Eric Brunson brunson at level3.net
Fri Feb 15 17:09:47 MST 2002

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

Is there a preferred way to get only the list of the non-method

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.


 Eric Brunson   brunson at level3.net   page-eric at level3.net  
tcA thgirypoC muinelliM latigiD eht detaloiv tsuj evah uoY

More information about the FRPythoneers mailing list