You can find the parent directory of a directory using the os module in Python. The os.path.dirname() function returns the parent directory of a given path. Here's an example:
main.py106 chars7 lines
Output:
main.py22 chars2 lines
In this example, the os.path.dirname() function returns the parent directory of the myproject directory. The result is assigned to the parent_dir variable which is then printed to the console.
gistlibby LogSnag