Two import questions in Python 3.0
kay.schluehr at gmx.net
Sun Jan 25 05:56:06 CET 2009
On 24 Jan., 18:51, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> Kay Schluehr wrote:
> > On 24 Jan., 09:21, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> >> If you run A.py as a script, it does not "know" it lives inside a package.
> >> You must *import* A for it to become aware of the package.
> >> Also, the directory containing the script comes earlier than PYTHONPATH
> >> entries in sys.path -- so watch for that case too.
> > Thanks, yes. I always make the same error thinking that a directory
> > with the ritual __init__ file is actually a package ( as some kind of
> > platonic entity ), something that is more obvious to me than it is to
> > the runtime. The relative import semantics introduced with Python 2.5
> > has made the error just visible that was hidden to me for about a
> > decade. Shit.
> Temper the language a bit. You lose your effectiveness by some people
> reading the color of your words, rather than their meaning in code.
Sigh, yes... sorry. I'm just too frustrated. Actually I don't even
know why the import machinery is such a mess and I don't want to spend
a huge amount of time ( like Brett Cannon ) to figure it out.
I'll spent a few hours of time writing a script that turns all
relative paths into absolute ones without changing the source
otherwise. Then I'm at least done with that and won't ever see the
"relative import in non-packages" exceptions anymore in any code I
touch ( I can also ignore __package__, -m and all the other
workarounds ). It's not the first time Python is in my way but this
time it hurts.
More information about the Python-list