Python os module is very helpful when need to go to a specific directory and create a directory.

For example print out the current directory


import os
current_directory = os.getcwd()
print("Current Directory:", current_directory)



More operating system-independent and navigate to a directory in a platform-independent way,


mport os

# Define the path relative to the user's home directory
# it will work well whatever you are in windows or linux 
directory= os.path.join(os.path.expanduser('~'), 'Documents')
print(directory)


We use essential cookies for website functionality and security. We also use cookies to analyze traffic.