Zed-King Institute
    All Notes

    O Level · Chapterwise Notes

    Chapter 7: File Processing

    Zed-King Study app · Free

    O Level students across India practise here, free

    Daily M1–M4 quizFull 100-question mocksAll-India rank
    Open the free app

    Google login · no Play Store needed

    🏆 Free All-India Sunday Mock · Sun, 29 Nov, 11 AM · CCC + O LevelRegister

    About this PDF

    Opening, reading and writing files, file modes and file-handling programs.

    This is part of the free O Level M3-R5.1 study material in the Zed-King Study Zone. You can read every page above in your browser, or download the file and study offline. Zed-King Group of Institute is a NIELIT Study Centre in Kaithal, Haryana, and all of this material follows the current NIELIT syllabus.

    Course
    O Level — NIELIT Foundation Diploma
    Module
    M3 — M3-R5.1: Programming and Problem Solving through Python
    Section
    Chapterwise Notes
    Format
    PDF — read online or download
    Price
    Free, no sign-up required

    Text from this PDF

    The opening pages as plain text — open the reader above for tables, diagrams and the full file.

    CHAPTER-3 File Processing File:- File is a collection of related records which is saved on the hard disk. When any data is written on a computer, it is first stored in its RAM (Random Access Memory)

    and when the computer is turned off, all that data gets lost and when that data is saved then it Stored permanently on the secondary storage device (hard drive) of the computer.

    1. High level file

    2. Low level file

    1. High Level File:- Library function is used in high level file, it can be understood by the user.

    2. Low Level File:- It is also called system oriented file, this file is managed through system calls.

    Data Storing mode:-

    1. Text file format

    2. Binary file format

    3. CSV File

    1. Text file format:- This is a human readable file, it can be edited through a text editor. In the text file, data is stored in the form of characters and lines. EOL (end of line) character is used to indicate the termination of the line in a text file which is terminated by a new line. The ASCII value of EOF is 26. All input functions do not read data after the EOF character.

    1. Binary file format:- This file format contains data like image, audio, video etc. is stored Operation on file:- To work on a file, the file is opened, then the data in the file is read or written and finally the file is closed.

    Some important operations to handle files in Python are given below-

    1. Opening File

    2. Closing File

    3. Reading File

    4. Writing File

    5. Append to a file

    6. Renaming File

    7. Deleting File

    1. Opening File When the data of a file has to be manipulated, the file is first opened. To open the file in Python, Python's in-built 'open()' method is used.

    Syntax:- obj #opens a file in given mode Parameters : There are 8 parameters for open() method but only 2 important parameters are given here.

    fileName : Here, along with the file name, its extension is also given. If the file is at the same location, then there is no need to give the path.

    mode : Here mode is given to open the file, if mode is not given then default is 'rl(reading) mode.

    f=open("file_name.extension_name", "mode")

    2. Closing File When the file is opened with open() method, then it is also closed by performing some operations on the file. 'Close()' method is used to close the file.

    Syntax fileObj.close()

    f=open("abc.txt","w")

    f.write("ak it solutionn")

    To open the file, opening mode has to be specified.

    There are many modes to open a text file which are as follows- ii. r iii. a iv. w+ i. w mode:- To input data in the file, the file is opened in write mode. If the file is already created then the previous data is erased and new data is written. If the file is not available then a new file is created. And data is written in it.

    ii. r mode:- It opens the file only in read mode, this is the default.

    iii. a mode:- This mode is used to work on already available files. This mode does not override (erase) the already available data, that is, it reaches the end without removing the data.

    If the file is not already available then a new file is created.

    iv. w+ mode:- The file is opened for reading and writing. If the file exists then it is overwritten and if the file does not exist then a new file is created.

    v. r+ mode:- The file is opened for reading and writing, the previous data is not deleted from the file, the file pointer goes to the beginning of the file.

    vi. a+ mode:- The file is opened for appending and reading. If the file already exists then it reaches the end without removing the data and if the file does not exist then a new file is created.

    More chapterwise notes for M3-R5.1

    Run these Python programs yourself — free

    Reading code is not the same as writing it. Type any program from these notes into our free online Python compiler (real Python 3 with NumPy, input() works), or study one of the explained programs with its output.

    Prepare for O Level with expert guidance

    Classroom training, practical labs and exam registration at Zed-King Institute, Kaithal.

    Drag me!