File Handling
File Handling
File Handling
Python 3.6.5
How to open a file?
Python has a built-in function open() to open a file. This
function returns a file object, also called a handle, as it is
used to read or modify the file accordingly.
Modes for Opening of Files
Mode Description
Open a file for writing. Creates a new file if it does not exist or truncates the file if it
'w' exists.
'x' Open a file for exclusive creation. If the file already exists, the operation fails.
Open for appending at the end of the file without truncating it. Creates a new file if
'a' it does not exist.
• Changing Directory
List Directories and Files
• List current directory