[Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this) (original) (raw)
Jean-Paul Calderone exarkun at divmod.com
Mon Apr 23 16:53:32 CEST 2007
- Previous message: [Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)
- Next message: [Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 23 Apr 2007 08:19:12 -0600, Steven Bethard <steven.bethard at gmail.com> wrote:
On 4/23/07, Steven Bethard <steven.bethard at gmail.com> wrote:
On 4/23/07, Barry Warsaw <barry at python.org> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Apr 23, 2007, at 9:21 AM, Christian Heimes wrote: > > > -1 on module > > > > I understand PEP 3020 correctly then sys.main will contain the dotted > > name of the module as string. > > > > Also module is already used in objects like classes. > > I'm not sure whether a general mechanism is necessary or not, but > I've always wished I could just do something like "import me" to > get the current module.
Well, you can always do:: import(name) That's not much more verbose. Of course, to make it work with packages, you have to write something like:: mod = import(name) for submodname in name.split('.')[1:]: mod = getattr(mod, submodname) I guess that's not so simple after all.
Maybe this indicates a problem with import. Twisted has something called namedAny, and I always use that, because it just works, unlike import, which seems to take too many arguments and has weird behavior for dotted names.
me = namedAny(name)
The inverse is also available (qual(me) == name), and is another function I've always thought it strange was missing from the stdlib.
Jean-Paul
- Previous message: [Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)
- Next message: [Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]