ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
dir() shows strange behaviour with VPython
by Gregor Lingl other posts by this author
Jul 13 2002 8:25AM messages near this date
Re: What does "Sparse is better than dense" mean? (Python Zen) | Re: dir() shows strange behaviour with VPython
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
> >>




-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Gregor Lingl
Gregor Lingl
Alex Martelli
Alex Martelli

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved