Extracting attributes from modules

Carsten Geckeler nospam at no.spam
Wed Dec 20 19:26:22 EST 2000

On Wed, 20 Dec 2000 plowboy_lifestyle at my-deja.com wrote:

> Hi,
>   I use python as an embedded scripting tool in the 3D
> modeling application called Blender and I'm looking for some
> clarification from a pro.
> I have this difficulty when I try learn about the various features of
> the embedded API from my scripts. A typical blender script looks
> something like this:
> import Blender
> from Blender import *
> print dir()
> this program is supposed to give me a list of the objects in the name
> space including everything from the module blender. The output looks
> something like this (hopefully I can explain all this without being
> application specific):
> ['Blender','Camera','Object','World',...etc.]
> so I explore further with
> print dir(Object)
> and I get:
> ['Get','GetSelected','Update','__doc__','__name__']
> if I use the get function I find out that it returns an object from
> within the modelling program, like a sphere or a mesh, whatever I'm
> using and I can manipulate it by setting various variable like "LocX" or
> "LocY" for the various locations of the 3D objects, like so:
> mySphere = Object.Get('theSphere')
> mySphere.LocX = mySphere.LocX + 5
> this program will have the effect of moving the object in space positive
> 5 units on the x axis.
> so this is my actual question; Even though I can find out about various
> attributes like LocX and etc. from the manuals for this application,
> there is no way for me to find them from python it seems, for example:
> print dir (Object.Get)
> print dir (mySphere)
> print dir (mySphere.LocX)
> print Object.Get.__doc__
> print mySphere.__doc__
> print dir(type(mySphere))
> all output an empty list or "none", even though
> print myShere.LocX
> works fine at printing out a floating point number.
> I'm only trying to get a list of names of attributes of the object but
> they seem hidden. Obviously I'm new to python. Can someone explain why
> this works this way?

Their probably not hidden, but mySphere is "only" an instance, so there
may be attributes or methods of the class or the base classes.  These
attributes don't show up with the dir() command.  Try the following:

print dir(mySphere)
print dir(mySphere.__class__)
for bc in mySphere.__class__.__bases__:
	print dir(bc)

Cheers, Carsten
Carsten Geckeler:  carsten dot geckeler at gmx dot de
To get proper email-address replace `dot' and `at' by the corresponding symbols.

More information about the Python-list mailing list