[Python-au] import stuff from parent directory
miked at dewhirst.com.au
Fri Dec 23 06:51:21 CET 2005
Thanks guys - learned heaps :)
All the best for 2006
> Daryl Tester wrote:
>> Mike Dewhirst wrote:
>>> How do I 'import ../prog'?
>> What you asked for, but probably not what you want:
>> import sys
>> sys.path.insert(0, '..')
>> import prog
>> Merry Christmas!
Nick Coghlan wrote:
>> Should I swallow hard and get into packages?
> Packages aren't that hard. Just put an empty "__init__.py" in
> working_dir and each of the subdirectories.
> Then "import prog" from within the subdirectories will try the
> subdirectory first, and when that fails, will try the parent directory.
> Only if both of those fail will it try the main sys.path, so you need to
> be careful not to shadow standard library modules that you want to use.
More information about the python-au