how to assign directory in python code example

Example 1: python create directory

# This requires Python’s OS module
import os

# 'mkdir' creates a directory in current directory.
os.mkdir('tempDir') 
# can also be used with a path, if the other folders exist.
os.mkdir('tempDir2/temp2/temp')

# 'makedirs' creates a directory with it's path, if applicable.
os.makedirs('tempDir2/temp2/temp')

Example 2: setwd python

os.chdir("/home/varun/temp")

Example 3: python get base directory

import os
os.path.dirname(os.path.realpath(__file__))

Example 4: how to use path to change working directory in python

pip install path
from path import Path

# set working directory
Path("/toWhereYouWantItToBe").cd()