xxxxxxxxxx
# print current working directory in python
import os
cwd = os.getcwd()
print(cwd)
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
# 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
cwd = os.getcwd()
my_file='image.png'
file_path = os.path.join(cwd, my_file)
file_path
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)