Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How do I get the parent directory in Python?

from pathlib import Path
Path(Path.cwd()).parent
Comment

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
Comment

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

Comment

python get parent directory

from pathlib import Path
Path('C:Program Files').parent
Comment

how to import from parent directory

import sys
  
# setting path
sys.path.append('../parentdirectory')
  
# importing
from parentdirectory.geeks import geek_method
  
# using
geek_method()
Comment

python import from parent directory

exec(open(<filename.py>).read())
Comment

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
Comment

python get parent directory

import os.path
os.path.dirname('C:Program Files')
Comment

how do i get parent directory python

from pathlib import Path
path = Path(Path.cwd())
print(path.parent)
Comment

import from parent directory python

from ... import nib
Comment

import from parent directory in python setup

from setuptools import setup, find_packages

    setup(name='myproject', version='1.0', packages=find_packages())
Comment

PREVIOUS NEXT
Code Example
Python :: what is seaborn in python 
Python :: numpy 3 dimensional array 
Python :: como comentar en Python? 
Python :: how to close a python program 
Python :: whatsapp online tracker python script 
Python :: kivy change window size 
Python :: random torch tensor 
Python :: excel write in row 
Python :: python change character in string 
Python :: get token from request django 
Python :: line length in flake8 
Python :: python nonlocal 
Python :: data compression in python 
Python :: python obfuscator 
Python :: cartesian product pandas 
Python :: python iterate list 
Python :: get column pandas 
Python :: ImportError: /usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_add_8 
Python :: django regexvalidator example 
Python :: how to redirect to previous page in django 
Python :: redirect parameters flask 
Python :: run code in python atom 
Python :: try except python not working 
Python :: how to set variable in flask 
Python :: np.random.RandomState 
Python :: python print 2 decimal places 
Python :: python isinstance list 
Python :: python get value from dictionary 
Python :: UTC to ISO 8601 with TimeZone information (Python 3): 
Python :: matplotlib bar chart 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =