Skip to content

Instantly share code, notes, and snippets.

import os # import the operating-system module
base_path = "" # introduce base_path this is configurable
rel_path = "" # introduce relative path the path within your WORKING directory
final_path = os.path.join(base_path, rel_path) # use this path for your work
import os # import the operating-system module
print(os.getcwd()) # print current working directory of the script
fp = open("my_dir/file.ext") # open some file in the current working directory i.e. where script lives
# how does it know the location of file.ext
fp.close()
import os # import the operating-system module
print(os.getcwd()) # print current working directory of the script
fp = open("file.ext") # open some file in the current working directory i.e. where script lives
# how does it know the location of file.ext
fp.close()