detmining name during an assignment

Ishwor ishwor.gurung at gmail.com
Fri Sep 18 19:25:00 CEST 2009


Jamie,
Hi.

> I have an app that uses Python scripting. When a user creates a new object:
>
> objName = newObject()

newObject should technically speaking be newClass() but nevermind :-)

> I'd like the newObject be able to use objName as its internal name.
> So, if a user says:
>
> cube1 = Cube()
>
>  A "cube1" object should apear in the scene list. I believe this means I need
> to determine that a namespace assignment is going on from inside the
> object's init code
> or by using properties.

A class's init code is like a constructor (guessing you know about
ctors here). Basically, initialising all the variables that particular
class uses. In this instance calling Cube( ) would cause it to call up
the __init__(self) function in Cube class and do whatever it does
there such as defining a variable, calling other initialisation
functions etc...

> I've searched the web but can't find a simple answer. Is there some
> way to use the inspect
> module get source code functoins? How would I get the code for "the

To get the source code for a function, you can manually inspect it. To
get the functions that a class exports, use can use
dir(object_of_a_class) in Python shell (this may not be what you want
but I write it anyway because I feel like writing today). You can also
run help(module_name_here) to see the docs+functions.

> current interpreter line"
> causing the init code to execute?

I am starting to suspect that you are very much asking for a debugger
;-) Look up pdb;a Python debugger.
-- 
Regards,
Ishwor Gurung



More information about the Python-list mailing list