xxxxxxxxxx
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")
xxxxxxxxxx
import os
#Get Current working Directory
currentDirectory = os.getcwd()
#Change the Current working Directory
os.chdir('/home/varun')
xxxxxxxxxx
# print current working directory in python
import os
cwd = os.getcwd()
print(cwd)
xxxxxxxxxx
# If by "current working directory" you mean
# the directory in which is saved the script in execution, then:
import os
cwd = os.path.dirname(os.path.realpath(__file__))
print(cwd)
xxxxxxxxxx
>>> import os
>>> os.getcwd()
'C:\\Program Files\\PyScripter'
>>> os.getcwdb()
b'C:\\Program Files\\PyScripter'
xxxxxxxxxx
import os
# Get current working directory
current_directory = os.getcwd()
print("Current Working Directory:", current_directory)