Answers for "python 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
15

python get current directory

import os

print(os.getcwd())
Posted by: Guest on March-02-2021
11

python get current file location

import os
os.path.dirname(os.path.abspath(__file__))
Posted by: Guest on May-11-2020
9

get path to current directory python

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

python list files in current directory

import os

files = os.listdir('.')
print(files)
for file in files:
  # do something
Posted by: Guest on November-04-2020
2

python get current directory

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Posted by: Guest on November-04-2020

Code answers related to "python get current directory"

Python Answers by Framework

Browse Popular Code Answers by Language