dir() shows strange behaviour with VPython

Gregor Lingl glingl at aon.at
Sat Jul 13 04:25:49 EDT 2002


I thought to understand the dir() function, but...

... when playing around with VPython I encountered the
following:

>>> from visual import *
Visual-2002-06-14
>>> s=sphere() # beautiful white sphere displayed immediately
>>> s
<Primitive object at 0x01563D34>
>>> dir(s)
['__class__', 'axis', 'blue', 'color', 'constr',
 'display', 'frame', 'green', 'name', 'pos', 'radius',
'red', 'rotate', 'up', 'visible', 'x', 'y', 'z']
>>> s.__methods__
['rotate']
>>> s.__dict__
{'__class__': <built-in method sphere of tuple object at 0x00A65590>}
>>> s.__members__
['axis', 'blue', 'color', 'display', 'frame', 'green',
'pos', 'radius', 'red', 'up', 'visible', 'x', 'y', 'z']
>>> s.name
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in ?
    s.name
AttributeError: name
>>>

So, what are 'name' and 'constr', which both do not appear
neither in s.__members__ nor in s.__dict__ nor in s.__methods__,
but in the list returned by dir(s)?

(Or: what is generally returned by dir() ?)

Perhaps there is somebody who can explain this.

Thanks, Gregor


In other words: what happens in the following example, should not
happen in my understanding:

>>> from visual import *
Visual-2002-06-14
>>> s = sphere()
>>> for att in dir(s):
        print att, ':',
        print type(eval('s.'+att))


__class__ : <type 'instance'>
axis : <type 'vector'>
blue : <type 'float'>
color : <type 'tuple'>
constr :
Traceback (most recent call last):
  File "<pyshell#46>", line 3, in ?
    print type(eval('y.'+att))
  File "<string>", line 0, in ?
AttributeError: constr
>>>







More information about the Python-list mailing list