Posts

Showing posts from May, 2021

PYTHON DIRECTORIES AND FILES MANAGEMENT

Image
DIRECTORIES AND FILES MANAGEMENT # If there are a large number of files to handle in python, we can arrange our code within different directories to make things more manageable. # A directory is a collection of files and sub directories. # Python has the os module that provides many useful methods to work with directories and files. # get current directory. getcwd() # This module returns the current working directory in the form of a string. # We can also use: getcwdb() # method to get it as bytes object. import os os.getcwd() os.getcwdb() print (os.getcwd()) # Changing directory. chdir() # We can change the current working directory by using this method. # The new path that we want to change into must be supplied as a string to this method. # We can use both forward slash(/) and backward slash (\) to separate path elements. os.chdir( 'C: \\ Python3' ) print (os.getcwd()) # List of directories and files. # All files and sub directories inside a direc

Popular posts from this blog

PIR SENSOR (PASSIVE INFRARED SENSOR)