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
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
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 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