Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get path to current directory python

import os
os.path.abspath(os.getcwd())
Comment

file path current directory python

#Python 3

#For the directory of the script being run:

import pathlib
pathlib.Path(__file__).parent.resolve()

#For the current working directory:

import pathlib
pathlib.Path().resolve()

#Python 2 and 3

#For the directory of the script being run:

import os
os.path.dirname(os.path.abspath(__file__))

#If you mean the current working directory:

import os
os.path.abspath(os.getcwd())
Comment

python os get dir path

from os import getcwd # only import "getcwd" from os

getcwd() # Get the current working directory
Comment

python get dir from path

import os
your_file_path = "D:yourdirpathfile.csv"
print(f"Dir:{os.path.dirname(your_file_path)}") 
#>>> Dir:D:yourdirpath
Comment

PREVIOUS NEXT
Code Example
Python :: python open web browser 
Python :: get gpu device name tensorflow 
Python :: django admin no such table user 
Python :: remove column from df 
Python :: cv2 grayscale 
Python :: install fastapi conda 
Python :: mac upgrade python to 3.8 
Python :: plotly not showing in jupyter 
Python :: pandas change column to a string 
Python :: python delay 
Python :: horizontal line matplotlib python 
Python :: how to add text in python turtle 
Python :: how to add legend to python plot 
Python :: make tkinter btn disable 
Python :: python program to find first n prime numbers 
Python :: split data validation 
Python :: python download file from url 
Python :: python plot frequency of column values 
Python :: unix to datetime python 
Python :: requests download image 
Python :: python check file extension 
Python :: Unable to locate package python-certbot-nginx 
Python :: how to move a column to the beginning in dataframe 
Python :: correlation plot python seaborn 
Python :: python os make empty file 
Python :: how to convert datetime to jdatetime 
Python :: pandas plotly backend 
Python :: add conda env to jupyter 
Python :: python rename file 
Python :: change size of selenium window 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =