[Python-Dev] Re: opcode performance measurements

M.-A. Lemburg mal@lemburg.com
Fri, 01 Feb 2002 11:21:14 +0100


Jeremy Hylton wrote:
> 
> >>>>> "GM" == Gordon McMillan <gmcm@hypernet.com> writes:
>   GM>       Heck, Marc-Andre tricks import so that pkg.mod is really
>   GM> pkg.attr where the attr turns into a mod when accessed. No
>   GM> problem, since it's only import that cares what it is. By the
>   GM> time it's used it's always global.attr.attr....
> 
> Not sure I understand what Marc-Andre is doing.  (That's probably true
> in general <wink>.)  A client of his code types "import foo.bar."
> foo is a module?  a package?  When the "bar" attribute is loaded
> (LOAD_ATTR) is turns into another module?

Take a look at e.g. mx.DateTime.__init__ and the included
LazyModule module for more background.

I don't really use that approach myself, but sometimes it can be
handy to be able to reference modules in packages without
requiring an import of them, e.g.

import mx.DateTime
date = mx.DateTime.Parser.DateTimeFromString('2002-02-01')

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/