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")
# 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)
# Import the os module
import os
# Print the current working directory
print("Current working directory: {0}".format(os.getcwd()))
# Change the current working directory
os.chdir('/tmp')
# Print the current working directory
print("Current working directory: {0}".format(os.getcwd()))
import os
print("File location using os.getcwd():", os.getcwd())
print(f"File location using __file__ variable: {os.path.realpath(os.path.dirname(__file__))}")