Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How do I get the parent directory in Python?

from pathlib import Path
Path(Path.cwd()).parent
Comment

python get parent directory

from pathlib import Path
Path('C:Program Files').parent
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

PREVIOUS NEXT
Code Example
Python :: python singleton class 
Python :: plot scattered dataframe 
Python :: get_queryset django rest framework 
Python :: how to overlap two barplots in seaborn 
Python :: github3 python 
Python :: python split string by specific word 
Python :: tensorflow 
Python :: check if string is python 
Python :: Tree Traversals inorder,preorder and postorder 
Python :: python capture stdout 
Python :: operator overloading python 
Python :: logger 
Python :: tables in jinja template 
Python :: discord bot python get message id 
Python :: strip plot 
Python :: join multiple excel files with python 
Python :: sum up list python 
Python :: comments in python 
Python :: python import function from file 
Python :: django edit object foreign key id 
Python :: define a function in python without arguments 
Python :: map vs apply pandas 
Python :: flow of control in python 
Python :: login required 
Python :: plotly express change legend labels 
Python :: python webview 
Python :: map in python 3 
Python :: python new 
Python :: python list clear vs del 
Python :: how to use str() 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =