Re: the name of a module in which an instance is created?
- From: Mardy <mardy@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Nov 2005 23:50:40 GMT
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__(cls.__module__)
I'm not sure I got your problem correctly, however see if this helps:
$ cat > test.py
class myclass:
name = __module__
^D
$ python
Python 2.3.5 (#2, Jun 19 2005, 13:28:00)
[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> a = test.myclass()
>>> a.name
'test'
This works, as we define "name" to be a class attribute.
Is this useful to you?
--
Saluti,
Mardy
http://interlingua.altervista.org
.
- Follow-Ups:
- Re: the name of a module in which an instance is created?
- From: Steven Bethard
- Re: the name of a module in which an instance is created?
- References:
- the name of a module in which an instance is created?
- From: Steven Bethard
- the name of a module in which an instance is created?
- Prev by Date: Re: Advice on distutils and distribution policies
- Next by Date: Re: Command line
- Previous by thread: the name of a module in which an instance is created?
- Next by thread: Re: the name of a module in which an instance is created?
- Index(es):