Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get directory of file python

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Comment

python get dir

import os 
#full path
dir_path = os.path.dirname(os.path.realpath(__file__))

#current dir
cwd = os.getcwd()
Comment

python how to get directory of script

import os
print(os.path.abspath(''))
Comment

python get directory of current script file

import os
os.path.abspath(__file__) # Directory of current python script
#Output will look something like: C:UsersUserNameDesktoppy-script.py
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 :: decision tree gridsearchcv 
Python :: flask migrate install 
Python :: pd max rows set option 
Python :: python matplotlib hist set axis range 
Python :: python loop through array backwards 
Python :: python datetime time in seconds 
Python :: change text color docx-python 
Python :: 1052 uri solution 
Python :: convert hex to decimal python 
Python :: python print dict new line 
Python :: get the system boot time in python 
Python :: python search string for word 
Python :: get index of list item in loop 
Python :: extend stack python 
Python :: pandas to tensor torch 
Python :: python print return code of requests 
Python :: python pandas replace nan with null 
Python :: plotly reverse y axis 
Python :: save timestamp python 
Python :: python keyboard press 
Python :: how to execute a cmd command in python 
Python :: how to iterate through a text file in python 
Python :: spacex 
Python :: django sort queryset 
Python :: python pop up box 
Python :: django create model from dictionary 
Python :: import fashion mnist keras 
Python :: position of legend matplotlib 
Python :: how to find duplicate numbers in list in python 
Python :: mark_safe django 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =