[Python-ideas] sys.path is a hack - bringing it back under control
techtonik at gmail.com
Mon Feb 20 11:31:21 CET 2012
On Mon, Feb 20, 2012 at 1:06 PM, Simon Sapin <simon.sapin at kozea.fr> wrote:
> I often find this in my scripts/projects, that I run directly from
>> DEVPATH =os.path.dirname(os.path.**abspath(__file__))
> You shouldn’t have to do that if you’re running 'python something.py'
But I did for some reason, and right now I can't even say if it was
Windows, Linux, FreeBSD, PyPy, IPython, gdb or debugging from IDE.
As initialized upon program startup, the first item of this list,
>> path, is the directory containing the script that was used to
>> invoke the Python interpreter. If the script directory is not
>> available (e.g. if the interpreter is invoked interactively or if the
>> script is read from standard input), path is the empty string,
>> which directs Python to search modules in the current directory
> The trick is to place the script in the directory that you want in the
> path, ie. next to top-level packages. But from your code above this seems
> to be the case already...
s/trick/hack/ and it will be just what I am saying. Not many Python
projects use this structure.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas