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 :: python working directory 
Python :: django slug int url mapping 
Python :: how to change frame in tkinter 
Python :: python sort dictionary by value 
Python :: msg.author discord.py 
Python :: python isset 
Python :: kivy button disable 
Python :: dataframe in python 
Python :: python capitalize every first letter 
Python :: data normalization python 
Python :: find the highest id in model django 
Python :: randomly shuffle array python 
Python :: how to get length of string in python 
Python :: how to take input for list in one line in python 
Python :: add two numbers in python 
Python :: how to get local ip in python 
Python :: How to append train and Test dataset in python 
Python :: pass a list to a function in python 
Python :: print inline output in python 
Python :: create an empty numpy array and append 
Python :: pandas groupby counts 
Python :: how to define piecewise function i python 
Python :: how to create an entry box on tkinter python 
Python :: how to create a set from a list in python 
Python :: python to uppercase 
Python :: find sum numbers in a list in python 
Python :: print colored text in python 
Python :: how to use drf pagination directly 
Python :: what is *args and **kwargs in django 
Python :: tweepy aut code 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =