CH 5
CH 5
CH 5
2. Each line of text is terminated (delimited) with a special There is no delimiter for a line in binary files.
character known as EOL (End Of Line) character.
3. In text files, some internal translations take place when There is no translation in binary files.
this EOL character is read or written.
4. In Python, by default, EOL is the newline character (‘\n’) There is no delimiter for a line in binary files.
or the carriage –return newline combination (‘\r\n’).
5. Text files are in human readable form. Binary files are not in human readable form.
6. Common extension: .txt Common extension: .dat
Q) What is file-object?
Ans:- Python’s open( ) function creates a file object (also known as file-handle) which serves as a
link to a file residing in your computer and makes it available for a number of different task.
For example: myfile = open(“data1.text”, ”r”)
NOTE
With r you can use single slashes in pathnames. Myfile = open(r”C:\temp\data1.txt”, “r”)
The prefix r makes it raw string that means there is no special meaning attached to any character.
Q) What is file-mode?
Ans:- A file-mode governs the type of operations (read/write/append) possible in the opened file.
i.e., it refers to how the file will be used once it is opened. It is specified in the open( ) function.
Syntax - <fileobject> = open(<path>, <file-mode>)
Removing the EOL ‘\n’ character from Removing the leading whitespaces from
the line read from the file the line read from the file
1. Absolute pathnames mentions the path Relative pathnames mention the paths
from the topmost level of the directory relative to current working directory. The
structure. dot(.) denotes the current directory and two
dots(..) denotes the parent directory.
2. C:\Users\HP\ GAMES\SAO\NOTES.DOC ..\SAO\NOTES.DOC