detmining name during an assignment

J

Jamie Riotto

I have an app that uses Python scripting. When a user creates a new object:

objName = newObject()

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.

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
current interpreter line"
causing the init code to execute?

Thanks very much in advance,
Jamie Riotto
 
S

Simon Forman

I have an app that uses Python scripting. When a user creates a new object:

objName = newObject()

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.

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
current interpreter line"
causing the init code to execute?

Thanks very much in advance,
Jamie Riotto

Save yourself a lot of trouble and just assign a name "manually":

class foo:
def __init__(self, name):
self.name = name


some_foo = foo("some_foo")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top