Use this tag for question regarding "data paths" and "file paths" in blender.

A link to the blender python API about data paths.

Regarding File Paths and Blender

...

Regarding File Paths and Python

Specifically the topic of how to get a valid file path using Python is worth stating explicitly. Python's os module is capable of joining file paths and extracting directory names or file names:

filename = 'some_file_name.extention'

# known as "POSIX" form (on linux or osx):
directory = '/home/username/Desktop'

# python on windows handles paths in two ways.
directory = r'c:\some\directory'  # the r is important
directory = 'c:/some/directory'  # (alternative)

# this will automatically join directories and a filename to
# produce a full file path
fullpath = os.path.join(directory, filename)

The current file's location is obtained using __file__, and os.path.dirname will return the full directory minus the filename

import os
current_file_path = __file__
current_file_dir = os.path.dirname(__file__)

to access a file in the same directory as this python file you do

other_file_path = os.path.join(current_file_dir, "other_file.ext")
with open(other_file_path) as f:
   ...

if there's a directory on the same path as the main python file you can get that by doing

other_file_path = os.path.join(current_file_dir, "directory", "other_file.ext")
with open(other_file_path) as f:
   ...
history | excerpt history