relative import broken?

Alan Isaac aisaac at american.edu
Thu May 3 13:08:56 EDT 2007


"Alex Martelli" <aleax at mac.com> wrote in message
news:1hxcdkq.47p2r6beuctcN%aleax at mac.com...
> Very simply, PEP 328 explains:
> """
> Relative Imports and __name__
>
> Relative imports use a module's __name__ attribute to determine that
> module's position in the package hierarchy. If the module's name does
> not contain any package information (e.g. it is set to '__main__') then
> relative imports are resolved as if the module were a top level module,
> regardless of where the module is actually located on the file system.
> """

To change my question somewhat, can you give me an example
where this behavior (when __name__ is '__main__') would
be useful for a script? (I.e., more useful than importing relative
to the directory holding the script, as indicated by __file__.)

Thanks,
Alan Isaac





More information about the Python-list mailing list