The goal of efficiency is more slack.

Friday, August 18, 2017

Creating paths in Python

Let's say you had this tree:
/home/me/example.com/passenger_wsgi.py
/home/me/example.com/virtualenv
In the Python script, to refer to the directory that is sibling to the script:
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'virtualenv')
Note that this will yield the same result even if the script is a symlink to a file located elsewhere, i.e. __file__ refers to the location of the symlink and not the original file.

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Powered by Blogger.
Scroll To Top