Question about imports and packages

Chris Angelico rosuav at gmail.com
Wed May 25 04:34:14 EDT 2016


On Wed, May 25, 2016 at 6:27 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I don't think this is that much different from the way other scripting
> languages handle it. E.g. bash. If I have a set of (say) shell scripts:
>
> fnord/
> +-- foo.sh
> +-- bar.sh
>
>
> where foo.sh runs bar.sh, but fnord is *not* on the PATH, the way you make it
> work is:
>
> - have foo.sh temporarily modify the PATH;
> - have foo.sh call bar.sh using an absolute pathname.
>
> That second option isn't available to Python, but then, .pth files aren't
> available to the shell :-)

The one obvious way with shell scripts is a *relative* pathname. You
can say "./bar.sh" (or, if you want to run something relative to the
script directory, some manipulation of path names and $0 will do that
for you). The best Python equivalent would be:

from . import bar

I'd very much like for that to be possible.

ChrisA



More information about the Python-list mailing list