problem(s) with import from parent dir: "from ../brave.py import sir_robin"

Carsten Haese carsten at uniqsys.com
Fri Feb 24 09:31:17 EST 2006


On Fri, 2006-02-24 at 09:10, per9000 wrote:
> Thanks,
> 
> I added an environment variable PYTHONPATH and added the holy folder
> with my script in. Works just perfectly.
> 
> But still: is there a way around this? (It is a lot easier to add
> "../../" in my code than make everyone else add this variable).

Yes.

>From http://docs.python.org/tut/node8.html#SECTION008110000000000000000:
"""
Actually, modules are searched in the list of directories given by the
variable sys.path [...]. This allows Python programs that know what
they're doing to modify or replace the module search path.
"""

In other words, your script may simply append other module locations
such as "../.." to sys.path.

-Carsten.





More information about the Python-list mailing list