relative import broken?

Alex Martelli aleax at mac.com
Mon Apr 30 23:14:35 EDT 2007


Alan Isaac <aisaac at american.edu> wrote:

> "Alex Martelli" <aleax at mac.com> wrote in message
> news:1hxcdkq.47p2r6beuctcN%aleax at mac.com...
> > To me, it makes sense: if a module is top-level, and thus not part of a
> > package (and __main__ in particular is always in that state), then
> > saying "import from the current package" has no well defined meaning,
> > because there IS no "current package".
> 
> Thanks for the explanations.
> I do not have an opinion because I have not really thought this through.
> 
> One of the things I was hoping for, however, was for a less hackish way
> for scripts bundled with a package to access the package modules.
> 
> That is, suppose I have directory ``mypackage`` with subdirectory
> ``scripts``.
> What is the pretty way for the scripts to access ``mypackage`` without
> assuming ``mypackage`` is in ``sys.path``?

I don't know of any "pretty" way -- I'd do it by path manipulation
(finding mypackage from os.path.abspath(__file__) and inserting its
_parent_ directory in sys.path).


Alex



More information about the Python-list mailing list