Answers for "how to assign directory in python"

39

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')
Posted by: Guest on February-24-2020
5

setwd python

os.chdir("/home/varun/temp")
Posted by: Guest on April-13-2020
1

python get base directory

import os
os.path.dirname(os.path.realpath(__file__))
Posted by: Guest on May-11-2020
4

how to use path to change working directory in python

pip install path
from path import Path

# set working directory
Path("/toWhereYouWantItToBe").cd()
Posted by: Guest on March-09-2020

Code answers related to "how to assign directory in python"

Python Answers by Framework

Browse Popular Code Answers by Language