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.

Related Posts:

  • List links in HTML filesThis Python script walks through a directory of HTML files and extracts all the links. It outputs one line per link with each line also containing the… Read More
  • Creating paths in PythonLet'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 t… Read More

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Powered by Blogger.
Scroll To Top