Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

pathlib current directory

from pathlib import Path
Path('.')
Comment

pathlib path of current file

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIR = BASE_DIR.joinpath('templates')
Comment

PREVIOUS NEXT
Code Example
Python :: python count total no of word in a text 
Python :: pandas string to number 
Python :: python remove articles from string regex 
Python :: python how to change an element in a multi dimensional list 
Python :: how to get a dataframe column as a list 
Python :: how to run django tests 
Python :: reverse python dict 
Python :: tkinter radio buttons 
Python :: python pil to greyscale 
Python :: how to use sum with range python 
Python :: python match phone number 
Python :: how to 404 custom page not found in django 
Python :: django rest 
Python :: pandas count freq of each value 
Python :: python for loop in one line 
Python :: OneHotEncoder(categorical_features= 
Python :: django iterate over all objects 
Python :: descending python dataframe df 
Python :: finding the index of an item in a pandas df 
Python :: Read XML file to Pandas DataFrame 
Python :: pasal 
Python :: python sqlite insert 
Python :: panda categorical data into numerica 
Python :: connection to server at "" (), port 5432 failed: timeout expired 
Python :: python add all items in list 
Python :: how to use print in python 
Python :: check strings last letter python 
Python :: how to fill a list in python 
Python :: convert data type object to string python 
Python :: module installed but not found python 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =