Answers for "how to get parent directory name in python"

0

How do I get the parent directory in Python?

from pathlib import Path
Path(Path.cwd()).parent
Posted by: Guest on November-29-2020
1

how to determine python project parent dir

import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir) 

import mymodule

OR 

import os, sys

sys.path.insert(1, os.getcwd()) 
import variables
Posted by: Guest on December-30-2020
0

how do i get parent directory python

from pathlib import Path
path = Path(Path.cwd())
print(path.parent)
Posted by: Guest on November-29-2020

Code answers related to "how to get parent directory name in python"

Python Answers by Framework

Browse Popular Code Answers by Language