[Python-ideas] sys.path is a hack - bringing it back under control

anatoly techtonik 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
>> checkout:
>> DEVPATH =os.path.dirname(os.path.**abspath(__file__))
>> sys.path.insert(0,DEVPATH)
> 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[0], 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[0] is the empty string,
>> which directs Python to search modules in the current directory
>> first.
> http://docs.python.org/py3k/**library/sys.html#sys.path<http://docs.python.org/py3k/library/sys.html#sys.path>
> 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.
anatoly t.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120220/032343d6/attachment.html>

More information about the Python-ideas mailing list