FILE HANDLING
FILES IN PYTHON
Python provides several built-in functions and methods for creating, opening, reading,
writing, and closing files.
FILE OPENING AND MODES
Syntax:
file = open("filename", "mode“)
Examples:
file = open("example.txt", "r")
file = open("example.txt", "w")
file = open("example.txt", "a")
file = open("example.txt", "rb")
FILE OPENING MODES
Modes Description
r Read Mode
w Write Mode
a Append Mode
t Text Mode
b Binary Mode
+ Concatenation (ab+,a+,w+,wb+)
x Opens- for exclusive creation.

Python_Filehandling_basic for beginners.pptx

  • 1.
  • 2.
    FILES IN PYTHON Pythonprovides several built-in functions and methods for creating, opening, reading, writing, and closing files.
  • 3.
    FILE OPENING ANDMODES Syntax: file = open("filename", "mode“) Examples: file = open("example.txt", "r") file = open("example.txt", "w") file = open("example.txt", "a") file = open("example.txt", "rb")
  • 4.
    FILE OPENING MODES ModesDescription r Read Mode w Write Mode a Append Mode t Text Mode b Binary Mode + Concatenation (ab+,a+,w+,wb+) x Opens- for exclusive creation.