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

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 :: python numba 
Python :: how to restart program in python 
Python :: how to merge two dataframes 
Python :: natural log and log base 10 in python 
Python :: convert string to utf8 python 
Python :: get first x characters of string python 
Python :: python datetime get all days between two dates 
Python :: circular array python 
Python :: save dataframe to a csv local file pyspark 
Python :: remove all integers from list python 
Python :: how to set up dataframe from csv 
Python :: python remove first item in tuple 
Python :: Row wise mean pandas 
Python :: python make directory tree from path 
Python :: python regex get string before character 
Python :: add 2 set python 
Python :: python naming conventions 
Python :: get first line of file python 
Python :: smtpauthenticationerror 
Python :: python reduce() 
Python :: dict itterator python recursive 
Python :: python time wait 
Python :: create a list of a certain length python 
Python :: print pandas version python 
Python :: find an element in pandas 
Python :: pandas shift all columns 
Python :: convert string to dictionary python 
Python :: flip key and value in dictionary python 
Python :: numpy array_equal 
Python :: pandas add list to dataframe as column 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =