1

I have a list of absolute paths that I would like to turn to relative paths in order to insert into a script that imports files.

# minimum example

current_directory = os.getcwd()
parent_parent_path = os.path.dirname(os.path.dirname(os.getcwd()))
absolute_path = '/Users/Documents/projects/packout_model/data/03june2022/validated_packout_2015_2021.xlsx'

# relative_path = .... # relative path for validated_packout_2015_2021.xlsx is what we would be looking for.

I have come across some good examples for getting a relative path, but I have not been able to find a way to always get the correct relative path from an absolute path and a current working directory.

user4933
  • 1,485
  • 3
  • 24
  • 42

0 Answers0