Data File Handling (Autosaved)
Data File Handling (Autosaved)
Handling
Why there is a need of
File Handling?
A file in itself is a bunch of bytes stored on some storage
device.
Binary CSV
Text Files
Files Files
Text Files
Stores information in ASCII or Unicode characters.
More secure.
Difference between Text files and Binary Files
Text File Binary File
Binary files are used to store binary
Text files stores information in ASCII
data such as images, audio, video and
characters.
text.
Each line of text is terminated with
a special character known as EOL (End of There is no delimiter in Binary File.
Line)
Text files are easy to understand
because these files are in human Binary files are difficult to understand.
readable form.
Binary files are faster and easier for a
Text files are slower than binary files. program to read and write than
the text files.
Text files are having extension .txt Binary files are having extension .dat
How to open a text file ?
FileObject =open(<filename>)
OR
FileObject =
open(<filename>,<mode>)
File Handle or Path to a Mode of
File object
created file a file
Example:
F = open(“myfile.txt”,r)
in a
Where,
Structure can be any sequence of Python. It can be either list or
dictionary.
FileObject is the file handle of the file, in which we want to
write.
pickle.load()
Used to the data from a file.
Syntax:
Where,
Structure can be any sequence of Python. It can be either list or
dictionary.
FileObject is the file handle of the file, in which we want to
write.
Operations performed on
Binary File
Update a Append a
record in a record in a
binary file binary file
How to write records in a Binary File
How to search records from a Binary File?
Random Access in Files
seek( )
tell( )
seek()
seek() function is used to change the position of the file handle (file
pointer) to a given specific position.
File pointer is like a cursor, which defines from where the data has
to be read or written in the file.