Here is class 12 computer science Unit 5 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 5 and for all chapters here.Watch all tutorials for chapter 5: Python Revision Tour.
“w” and “a” modes are the writing methods in file. “w” is method in which the new content overlap the previous content and write the new content in the file.“a” is method in which the new content is appended in file that is without deleting the previous content.
File-object is very important in python as it provides user the reference to the existing file and also with several access options such as writing, reading and many more. It gives direct option to act on hardware memory.
f1 = open("file_path", 'r')
f1 is the file_object to access and manipulate the file content.
File open() function opens the access to the existing file and also create new file to user to perform various task on the file content.For example various operation are ‘w’ (write), ‘a’ (append), ‘r’ (read), ‘x’ (new).
File close() function close the access to the specific file provided that file was open.
file_object = open('file_name', 'mode') #creating access of the
file_object.close() #closing the access to the file_object
f = open(r"C:\Myfiles\Textl.txt", 'r+')
This open the file with path provided and 'r+' indicate the read and write mode access. r prefix indicate the raw string that no special meaning to character.
f = open("C:\\Myfiles\\Textl.txt", 'r+')
In this double slash '\\' suppress special meaning of '\'.
(i) When the mentioned file does not exist then –‘r’ in this mode error will generate as file do not found.‘w’ in this mode a new file will be created with mentioned name.
(ii) when the mentioned file does exist then ‘r’ in this mode no changes is occurred.‘w’ in this mode the data is either appended or truncated.
File mode provides the various kind of access to the user after the file is opened, to apply on the data in the file. A number of file operations can be performed on the bases of file mode as mentioned below:
In binary mode the file and its content is stored in the same format as the data is stored in the main memory. Here no encoding and the data conversion is held and addressing of the data is done accordance to the IEEE. It also offers advantage in terms of the speed access to the fetching and loading of the content.
In the text mode the content is stored in the ASCII and Unicode characters and here the end of each line is specified with special character called EOL. In this the transition on the data take place as of conversion and less prone to data get corrupted as of binary mode.
Text file is more preferred over the binary file as the content in text file is more readable by user easily and ported to different type of system. In this mode less chance of data corruption occur.
(a) f = open("BOOK.TXT", 'r')
(b) f = open("BOOK.TXT", 'w')
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page