On May 3, 10:08 am, "Alan Isaac" <[EMAIL PROTECTED]> wrote:
> "Alex Martelli" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > 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__.)

Do you realize it's a different behaviour and it won't work for some
packages? One possible alternative is to assume empty parent
package and let from . import foo work but not
from .. import bar or any other upper levels. The package author
should also realize __init__.py will be ignored.

  -- Leo

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to