Import 'filename'? (was Re: Cross-reference 'import' in a class hierarchy)
Greg Ewing (using news.cis.dfn.de)
ckea25d02 at sneakemail.com
Tue Apr 8 21:13:47 EDT 2003
Chris Reedy wrote:
> I had to think about this one for a while. Here's the issue I see:
>
> What exactly does import '../foo/ook.py' actual do?
You're being distracted by a red herring, I think. What
I took the original post to mean was doing the equivalent
thing in the Python module namespace, not the file
system namespace.
Some suitable syntax would need to be devised,
perhaps
import ..foo.ook
although I'm not sure how you would refer to the
imported module after that... maybe an "as" clause
should be mandatory in this case?
If you want to work in the file system namespace, you
can already do that:
ook = __import__("../foo/ook.py")
> Based on some reading in the email archives, there is clearly a desire
> (maybe a mandate by the BDFL) that some sort of correspondence be
> guaranteed to exist between the above four definitions (especially 1, 2,
> and 3).
I sometimes wonder whether the Python module namespace and
the file system should be one and the same thing. I certainly
believe that PYTHONPATH is a mistake -- the environment required
for a program to function correctly is a property of the program
itself, not of the user's personal settings.
Something better is needed, I'm just not sure exactly what
yet.
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list