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 :: make button in tk 
Python :: python == vs is 
Python :: python split string by specific word 
Python :: python change all values in nested list 
Python :: prime numbers upto n in python 
Python :: check if text is python 
Python :: traversal tree in python 
Python :: python how to create a function 
Python :: is there a null data type in python 
Python :: lambda 
Python :: api testing python 
Python :: Sendgrid dynamic templating 
Python :: remove whitespace method 
Python :: numpy rolling 
Python :: join multiple excel files with python 
Python :: upgrade python version windows 
Python :: how to find the last occurrence of a character in a string in python 
Python :: pivot table pandas 
Python :: sqlalchemy function for default value for column 
Python :: python built in libraries 
Python :: selecting a specific value and corrersponding value in df python 
Python :: python map 
Python :: os.path.join 
Python :: __dict__ 
Python :: python strings 
Python :: create new spreadsheet 
Python :: python 3 
Python :: rotate matrix 90 degrees clockwise in python 
Python :: generator expression 
Python :: python transpose 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =