Hacker News new | ask | show | jobs
by ptx 4010 days ago
> Why is a relative path in the PYTHONPATH necessarily bad practice? It's not a rhetorical question, I am genuinely curious.

Let's say you reimplement ls in Python. You then use your shiny new program to have a look at some downloaded files:

  $ ../utils/ls.py 
  ['hello.txt', 'os.py']
So far so good. Now let's try it with PYTHONPATH set to include the current directory:

  $ PYTHONPATH="." ../utils/ls.py 
  Boom! Your box is mine!
  ['no', 'files', 'for', 'you']
1 comments

A caveat of the approach is that you must run the script from the project's folder.

This is apparently an unacceptable limitation for some people, judging by the responses to the article - however for others it's not.