Skip to content

Instantly share code, notes, and snippets.

@pandorica-opens
Created October 26, 2020 11:57
Show Gist options
  • Select an option

  • Save pandorica-opens/c05fb5a0527e193e6293274f9022a6f5 to your computer and use it in GitHub Desktop.

Select an option

Save pandorica-opens/c05fb5a0527e193e6293274f9022a6f5 to your computer and use it in GitHub Desktop.
The parent_directory function returns the name of the directory that's located just above the current working directory.
import os
def parent_directory():
# Create a relative path to the parent
# of the current working directory
os.chdir('..')
relative_parent = os.path.abspath(os.getcwd())
# Return the absolute path of the parent directory
return relative_parent
print(parent_directory())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment