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 in a python terminal

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 :: python syntaxerror: unexpected character after line continuation character 
Python :: pip install module for specific python version 
Python :: class object 
Python :: Restrict CPU time or CPU Usage using python code 
Python :: python max of two numbers 
Python :: del(list) python 
Python :: add python to path windows 10 
Python :: django cache framework 
Python :: enum 
Python :: python click activator 
Python :: bar break matplotlib 
Python :: replace NaN value in pandas data frame 
Python :: Class 10: Conditional Statements in Python [IF, ELIF, ELSE] 
Python :: copy something character ubntil a specific character in python 
Python :: Missing Data Plotly Express px.data 
Python :: Add one to a column pands 
Python :: pandas get indices of mask 
Python :: python glob sort numerically 
Python :: how to stop a while loop in opencv 
Python :: check package without importing it python 
Python :: numpy array filter and count 
Python :: pandas add prefix to some range of columns 
Python :: gdal warp and glob through directory 
Python :: flask run function every minute 
Python :: install first person controller python 
Python :: How to download images from the OIDv4 in Anaconda Promt 
Python :: numpy array values not updateing 
Python :: cvhaardetectobjects 
Python :: python3 netifaces get current interface 
Python :: remove repetitive characters from the specified column of a given DataFrame 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =