organizing your scripts, with plenty of re-use
ethan at stoneleaf.us
Sun Oct 11 01:31:48 CEST 2009
Gabriel Genellina wrote:
> En Sat, 10 Oct 2009 05:57:08 -0300, Steven D'Aprano
> <steve at remove-this-cybersource.com.au> escribió:
>> On Fri, 09 Oct 2009 16:37:28 -0700, Buck wrote:
>>> Here's a scenario. A user does a cvs checkout into some arbitrary
>>> directory and sees this:
>>> +-- python/
>>> +-- animals.py
>>> +-- mammals/
>>> +-- horse.py
>>> +-- otter.py
>>> +-- reptiles/
>>> +-- gator.py
>>> +-- newt.py
>>> +-- misc/
>>> +-- lungs.py
>>> +-- swimming.py
>>> These are all runnable scripts that "just work" with no extra effort or
>>> knowlege, both in the testing scenario above, and for normal users that
>>> run it from some central location (maybe "/tools/mycompany/bin/
>>> The frustrating thing, for me, is that all these requirements are met if
>>> you leave the scripts in jumbled into a flat directory.
>> I bet that's not true. I bet that they Just Work only if the user cd's
>> into the directory first. In other words, if you have all your scripts in
>> the directory /tools/mycompany/bin/scripts, this will work:
>> $ cd /tools/mycompany/bin/scripts
>> $ animals.py
>> but this won't:
>> $ cd /home/username
>> $ /tools/mycompany/bin/scripts/animals.py
>> In the first case, it works because the current working directory is
>> included in the PYTHONPATH, and all the modules you need are there. In
>> the second, it doesn't because the modules aren't in either the current
>> directory or any other directory in the PYTHONPATH.
>> That's my prediction.
> Mmm, I predict you won't have much success in your new fortune teller
> career... :)
> You got it backwards. At least on Windows, the current directory
> *isn't* on the Python path, but the directory containing the script
> *is* included.
> So both alternatives above work.
Are you sure?
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
['', <-- current directory?
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
['C:\\temp', <-- hmmm, not the current directory
I just love learning new things! Thanks, Gabriel!
More information about the Python-list