Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get path to current directory python

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

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

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

python find dir

import os.path
from os import path

def main():

	print ("Is it File?" + str(path.isfile('guru99.txt')))
	print ("Is it File?" + str(path.isfile('myDirectory')))
if __name__== "__main__":
	main()
Comment

PREVIOUS NEXT
Code Example
Python :: check if string match regex python 
Python :: loads function in json python 
Python :: simple heatmap 
Python :: python curses for windows 
Python :: logistic regression algorithm 
Python :: how to take space separated input in pyhon dicationary 
Python :: code 
Python :: convert string to int dataframe column 
Python :: python3.8 
Python :: python string to operator 
Python :: python library for downsampling a photo 
Python :: fizz buzz 
Python :: django jazzmin pypi 
Python :: django model query join 
Python :: python isin 
Python :: covariance in python 
Python :: isolationforest estimators 
Python :: from django.core.management import execute_from_command_line ImportError: No module named django.core.management 
Python :: pandas if value present in df index 
Python :: nltk 
Python :: python prettytable 
Python :: download files from url in flask 
Python :: numpy arange float step 
Python :: print all variables jupyter notebook 
Python :: merge two sorted lists into one sorted list 
Python :: python regex find 
Python :: fill zeros left python 
Python :: cookies in django 
Python :: abstarct class python 
Python :: how delete element from list python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =