Answers for "os.path get current directory"

24

get wd in python

import os

path = os.getcwd()

print(path)
# /Users/mbp/Documents/my-project/python-snippets/notebook

print(type(path))
# <class 'str'>
Posted by: Guest on January-26-2020
9

get path to current directory python

import os
os.path.abspath(os.getcwd())
Posted by: Guest on September-16-2020
8

get directory of file python

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Posted by: Guest on April-03-2020
0

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())
Posted by: Guest on August-16-2021
0

path of current working directory with os module python

import os
cwd = os.getcwd()

my_file='image.png'
file_path = os.path.join(cwd, my_file)
file_path
Posted by: Guest on July-04-2021
-2

python os get dir path

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

getcwd() # Get the current working directory
Posted by: Guest on June-15-2020

Python Answers by Framework

Browse Popular Code Answers by Language