Get current directory python

Code examples

24
0

get wd in python

import os

path = os.getcwd()

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

print(type(path))
# <class 'str'>
15
0

working directory python

import os
cwd = os.getcwd()
8
0

python get current directory

import os

print(os.getcwd())
5
0

get diroctary in python

import os
cwd = os.getcwd()
print(cwd)
3
0

get path to current directory python

import os
os.path.abspath(os.getcwd())
2
0

get current directory python

import os
current_working_directory = os.getcwd()
print(current_working_directory) # should print the cwd

""" Bonus: If you want to change cwd, without moving file,
use the following method"""
os.chdir("path/to/directory")

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................