2. INTRODUCTION
• Files help to store the information
permanently.
• A file in itself is a bunch of bytes stored on
some storage device like hard – disk,some storage device like hard – disk,
thumb – drive, etc.,
3. DATA FILES
• The data files are the files that store data
pertaining to a specific application, for
later use.
• Types :• Types :
– Text Files
– Binary Files
4. TEXT FILES
• A text files stores information in ASCII or
characters.
• Each line of text is terminated (Delimited)
with a special character known as EOL (end
of Line) character.of Line) character.
• Some internal translations take place when
this EOL character is read or written.
• EOL character
– By default, newline character (‘n’) or carriage –
return, newline combination (‘rn’)
5. BINARY FILES
• A binary files is a file that contains
information in the same format in which the
information is held in memory.
• There is no delimiter for a line,
• No translations occur in binary files.• No translations occur in binary files.
• Binary files are faster and easier for a
program to read and write than are text files.
• As long as the file doesn’t need to be read by
people or need to be ported to a different type
of system, binary files are the best way to
store program information
8. • A file object is also known as File Handle.
• Python’s open() function creates a file object which serves a
link to a file residing on your computer.
• The first parameter - Path to file.
• Second Parameter – Mode• Second Parameter – Mode
• r - read
• w – write
• a - append
• Single
10. File Object / File Handle
• File objects are used to read and write data to a file on
disk
• A file object is a reference to a file on disk. It opens and
makes it available for a number of different tasks.
• A python program can work with files stored on• A python program can work with files stored on
hardware through file object only.
12. Closing Files
• Syntax :
• Example :
outfile =open(“Master.txt”, “r”)
• A close() function break the link of file – object and the file on the
hard disk.
• After close(), no tasks can be performed on that file through the file
– object ( or file handle)
13. Reading from files
• Before read from a file, be opened and
linked via a file –object or file handle.