import os
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
import os
cdir = os.getcwd() # it will return current working directory
print("Previous_dir",cdir)
# Previous_dir C:Users..Desktoppython
os.chdir('C:/Users/../Desktop/desire_folder') #chdir used for change direcotry
print("Current_dir",cdir)
# Current_dir C:Users..Desktoppython eamspirit
import os
path = "C:UsersYourDirectory"
os.chdir(path)
import os
os.chdir(new_working_directory)
os.chdir(os.path.dirname(__file__))
# 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()))
pip install path
from path import Path
# set working directory
Path("/toWhereYouWantItToBe").cd()
>>> os.chdir('C:Python33')
>>> print(os.getcwd())
C:Python33
# Import the os module
import os
# Get the current working directory
cwd = os.getcwd()
# Print the current working directory
print("Current working directory: {0}".format(cwd))
# Print the type of the returned object
print("os.getcwd() returns an object of type: {0}".format(type(cwd)))