Not Sure This Can Be Done...

MrJean1 MrJean1 at
Wed Apr 2 01:49:02 CEST 2008

In any script upon startup, sys.path[0] contains the full path of the
directory where the script is located.  See <
lib/module-sys.html> under 'path'.

it should be straightforward from here (untested though).  In each
script, get the sys.path[0] string, split it using os.path, replace
the last item with 'tools' and join again with os.path.  If the
resulting string is not in sys.path, insert it after sys.path[0].

/Jean Brouwers

On Apr 1, 1:57 pm, gamename <namesagame-use... at> wrote:
> Hi,
> I generally have several copies of the same development environment
> checked out from cvs at any one time.  Each development tree has a
> 'tools' dir containing python modules.  Scattered in different places
> in the tree are various python scripts.
> What I want to do is force my scripts to always look in the closest
> 'tools' dir for any custom modules to import. For example:
> tree1/tools
> tree1/my_scripts/
> tree2/tools
> tree2/my_scripts/
> How can I make '' always look in '../../tools' for custom
> modules? My preference would be to avoid changing the '' script
> and have some way to resolve it via the environment (like PYTHONPATH,
> or .pth files, etc.).
> Anyone have any ideas?
> TIA,
> -T

More information about the Python-list mailing list