Professional Documents
Culture Documents
Introduction
As we know, Files are an essential part of computers. Everything
stored in the computer is saved in files. These files are a collection of
bytes stored in computers. Data can be represented in specific forms
in files. These files can be accessed at any time. These files are saved
with an extension or file types. They need a specific program to read
data and write data.
For Ex. Documents can be opened and read through Word Processing
software such as MS Word, OO Writer, Word Star, etc.
1. Creation of files
2. Opening files
3. Reading files
4. Writing files
5. Appending data in files
6. Deleting Data from files
7. Creating copy
8. Updating files data
Text Files:
Open a text file:
Syntax:<file object> = open(file_name,access_mode)
file object : It is just like a variable or object
open(): It is a function with two parameters.
Note:
1. ‘+’ sign is used to open the file for both modes reading and writing
after access_mode. When it is used the file pointer will be at the
beginning of the file
2. ‘b’ along with above modes to work with binary files
Example:
f = open(“MyFile.txt”,”r”) – Open file for reading
f = open(“MyFile.txt”,”w”) – Open file for writing
Reading file:
Python provides the following functions for reading files:
1) read(): To read the whole file, take a look in the following
example.