Re: the name of a module in which an instance is created?

2005-11-22 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote: ... > Unfortunately, no, this is basically what I currently have. Instead of > a.name printing 'test', it should print '__main__'. I want the name of > the module in which the *instance* is created, not the name of the > module in which the *class* is

Re: the name of a module in which an instance is created?

2005-11-22 Thread Steven Bethard
Mardy wrote: > I'm not sure I got your problem correctly, however see if this helps: > > $ cat > test.py > class myclass: > name = __module__ > ^D > [snip] > > >>> import test > >>> a = test.myclass() > >>> a.name > 'test' > > This works, as we define "name" to be a class attribute. > Is th

Re: the name of a module in which an instance is created?

2005-11-21 Thread Mardy
Hi Steven, Le die Mon, 21 Nov 2005 11:37:37 -0700, Steven Bethard ha scribite: [...] > In the basic situation, where the instance is created in the same module > as the class, I can figure out 'mod' and 'name' like:: > > cls = type(self) > name = cls.__module__ > mod = __import__(c

the name of a module in which an instance is created?

2005-11-21 Thread Steven Bethard
The setup: I'm working within a framework (designed by someone else) that requires a number of module globals to be set. In most cases, my modules look like: (1) a class definition (2) the creation of one instance of that class (3) binding of the instance methods to the appropriate module global