PPT
PPT
1. Introduction
2. Text file
3. Binary file
4. Opening a File
5. Closing a File
6. Importance
7. Common Errors
8. Applications
9. Appending to files
10.conclusion
INTRODUCTION
File handling is a fundamental concept in programming
that enables programs to store, access, and manipulate
data in files on a computer.
Most computer programs work with files, because files
help in storing information.
Every programming language offer some provision to
use in create files through programs
DATA FILES
+The data files are the files that stores data pertaining to
specific application, for later use.
+The data file can be stored in 3 ways:
1. Text files
2. Binary files
3. CSV files
TEXT FILE
+ A text file stores information in ASCII or Unicode
character.
+ Each line of text is terminated with a special character
known as EOL character.
+ Some internal translations take place when this EOL
character is read or written.
+ In python, by default, this EOL character is the newline
character or carriage-return, newline combination.
BINARY FILE
+It is just a file that contains information in the same
format in which the formation is held in memory
+There is no delimiter for a line.
+Also no translations occur in binary files.
+Binary file are faster and easier for a program to read
and write than are text files.
+As long as 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 ways to store program information.
OPENING A FILE
+In data file handling through Python, the first thing that
you do is open the file. It is done using open() function
as per one of the following syntaxes:
<file_objectname>=open(<filename>)
<file_objectname>=open(<filename>,<mode>)
+Python’s open() function creates a file object which
serves as link to a file residing on your computer.
CLOSING A FILE
+A close() function breaks the link of file-object and the file on
the disk.
+An open file is closed by calling the close() method of its file-
object.
+Closing file is important.
+In Python, files are automatically closed at the end of program
but it is good practice to get into the habit of closing it.
+After close(), no tasks can be performed on that file through
the file-object.
+General form for closing a file
<fileHandle>.close()
IMPORTANCE OF FILE HANDLING
+Data Persistence: File handling allows data to be stored
permanently, enabling programs to access and use the data
even after the program has stopped running.
+Efficient Data Management: It helps in organizing, storing,
and retrieving data systematically for easy access and
processing.
+Log and Configuration Storage: Files are commonly used to
store logs, user preferences, and application settings for
consistent functionality.
+Resource Optimization: Proper file handling ensures
efficient use of system resources, preventing data loss and
corruption.
+Application Development: File handling is essential for
COMMON ERRORS IN FILE
HANDLING
+File Not Found Error
+Permission Denied Error
+File Already Exists Error
+File Is Opened Elsewhere
+End-of-File Error
+Data Corruption
+Invalid File Path or Name
+Encoding Errors
+Insufficient Disk Space
+IO Error/ Input-Output Error
CONCLUSION
+File handling is a crucial aspect of programming
that allows applications to interact with data in a
persistent and organized manner. By enabling
the creation, reading, writing, and management
of files, it ensures data is stored efficiently,
accessible over time, and securely managed. Its
significance spans a wide range of applications,
from storing user preferences and configuration
settings to maintaining log files and processing
large datasets.
THANK YOU