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 get parent directory

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

python import from parent directory

exec(open(<filename.py>).read())
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

get parent of current directory python

In [4]: from os.path import dirname

In [5]: dirname('/home/kristina/desire-directory/scripts/script.py')
Out[5]: '/home/kristina/desire-directory/scripts'

In [6]: dirname(dirname('/home/kristina/desire-directory/scripts/script.py'))
Out[6]: '/home/kristina/desire-directory'
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 :: how to make an infinite loop python 
Python :: how to write the character from its ascii value in python 
Python :: pandas profile report python 
Python :: instance variable in python 
Python :: dataframe KeyError: 
Python :: colorbar font size python 
Python :: python - change the bin size of an histogram+ 
Python :: how to cout in python 
Python :: pyqt5 keypressevent 
Python :: python all lowercase letters 
Python :: how to do swapping in python without 
Python :: how to simplify fraction in python 
Python :: pandas pass two columns to function 
Python :: python series to list of string 
Python :: how to convert the date column from string to a particular format in python 
Python :: pandas dataframe froms string 
Python :: program to print duplicates from a list of integers in python 
Python :: setting urls 
Python :: numpy check if an array is all zero 
Python :: python check tuple length 
Python :: tensorflow adam 
Python :: ++ python 
Python :: distance between numpy arrays 
Python :: children beautiful soup 
Python :: python lambda 
Python :: python stack 
Python :: pandas check if column is sorted 
Python :: can list comprehenios contain else 
Python :: python django model range validation 
Python :: python show charracter code 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =