Relative paths in Python

In the file that has the script, you want to do something like this: This will give you the absolute path to the file you’re looking for. Note that if you’re using setuptools, you should probably use its package resources API instead. UPDATE: I’m responding to a comment here so I can paste a code sample. 🙂 … Read more

Relative paths in Python

In the file that has the script, you want to do something like this: This will give you the absolute path to the file you’re looking for. Note that if you’re using setuptools, you should probably use its package resources API instead. UPDATE: I’m responding to a comment here so I can paste a code sample. 🙂 … Read more

Python list directory, subdirectory, and files

Use os.path.join to concatenate the directory and file name: Note the usage of path and not root in the concatenation, since using root would be incorrect. In Python 3.4, the pathlib module was added for easier path manipulations. So the equivalent to os.path.join would be: The advantage of pathlib is that you can use a variety of useful methods on paths. If you use the concrete Path variant you can also do actual OS … Read more

Relative paths in Python

In the file that has the script, you want to do something like this: This will give you the absolute path to the file you’re looking for. Note that if you’re using setuptools, you should probably use its package resources API instead. UPDATE: I’m responding to a comment here so I can paste a code sample. 🙂 … Read more