PYTHON
How do I get the parent directory in Python?
from pathlib import Path
Path(Path.cwd()).parent
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
python import file from parent directory
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
python get parent directory
from pathlib import Path
Path('C:Program Files').parent
how to import from parent directory
import sys
# setting path
sys.path.append('../parentdirectory')
# importing
from parentdirectory.geeks import geek_method
# using
geek_method()
python import from parent directory
exec(open(<filename.py>).read())
import file from parent directory python
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../db.py
import db
python get parent directory
import os.path
os.path.dirname('C:Program Files')
how do i get parent directory python
from pathlib import Path
path = Path(Path.cwd())
print(path.parent)
import from parent directory python
import from parent directory in python setup
from setuptools import setup, find_packages
setup(name='myproject', version='1.0', packages=find_packages())