Overview about data file handling let us Revise in python for class 12 cbse computer science

Overview about data file handling let us Revise 


A file in itself is a bunch of bytes stored on some storage devices like hard-disk, thumb-drive etc.

The data files can be stored in two ways: (i) Text files (ii) Binary files.

A text file stores information in ASCII or Unicode characters, where each line of text is terminated, (delimited) with a special character known as EOL (End of Line) character. In text files some internal translations take place when this EOL character is read or written.

A binary file is just a file that contains information in the same format in which the information is held in memory, i.e., the file content that is returned to you is raw (with no translation or no specific encoding). 

The open() function is used to open a data file in a program through a file-object (or a file-handle). 

A file-mode governs the type of operations (e.g., read/write / append) possible in the opened file i.e., it refers to how the file will be used once it's opened. 

A text file can be opened in these file modes 'r', 'w', 'a', 'r+", "w+', 'a+35

A binary file can be opened in these file modes: 'rb', 'wb', 'ab', r+b' (rb+'), 'w+b'('wb+'), 'a+b'('ab+), The three file reading functions of Python are read(), readline(), readlines()

While read() reads some bytes from the file and returns it as a string, readline() reads a line at a time and readlines() reads all the lines from the file and returns it in the form of a list.

The two writing functions for Python data files are write() and writelines(). While write() writes a string in file, writelines() writes a list in a file.

The input and output devices are implemented as files, also called standard streams.

There are three standard streams: stdin (standard input), stdout (standard output) and stderr (standard error)

The absolute paths are from the topmost level of the directory structure. The relative paths are relative to current working directory denoted as a dot(.) while its parent directory is denoted with two dots(..).

Post a Comment

If you any doubts, Please let me know

Previous Post Next Post