Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

handwritten notes

Rating
-
Sold
-
Pages
8
Uploaded on
20-06-2024
Written in
2023/2024

PPS (Post-Scriptum) handwritten notes refer to additional information or comments added after the main body of a written document. These notes are typically handwritten to emphasize important details, provide clarifications, or include supplementary thoughts that enhance the understanding of the main content. They can serve various purposes such as elaborating on complex ideas, offering alternative perspectives, or addressing specific questions that arise from the primary text. PPS notes are valuable for expanding upon key points and ensuring comprehensive communication. They often reflect the author's insights or responses to reader queries, contributing to a more thorough and nuanced discussion of the topic at hand.

Show more Read less
Institution
Course

Content preview

PPS UNIT-6 FILE HANDLING AND DICTIONARY (Questions and Answers)

Q.1 what are files. Why do we need them?
Answer-
Files and Need of files-
1. A file is collection of data stored on a secondary storage device like hard disk.
2. Console oriented I/O operations pose two major problems-
a. Time consuming
b. Entire data lost when program terminate.
3. When program is being executed, its data is stored in RAM
4. RAM can accessed faster by CPU, but RAM is volatile/ not permanent storage
5. If you need data in future then you need to store data on permanent storage in files.
6. Files stored in name locations on storage media.
7. To use file first open file, read or write it and then finally close it.
8. File is used because real life applications involve large amounts of data.
Q.2 Differentiate between absolute path and relative path.
Answer-




Q.3 What are the types of files. or Explain Text file and Binary file.
Answer-
Text File-
1. It is stream of characters that can be sequentially processed by a computer in forward direction.
2. File open for read, write and append operations, but one at a time
3. Each line contains 255 characters
4. Each line ends with newline character ‘\n’
5. Each file ends with end of file marker(EOF)
6. Text files processed sequentially.
7. Example- 123 stored in 3 bytes
Binary File-
1. Binary file is a file which contains any type of data enclosed in binary form for computer storage and processing
purpose.
2. It includes files such as text, audio, video, images, pdfs, zip files.
3. Binary files also referred as a character stream.
4. Binary file does not require any special processing.

, 5. Binary file can be either processed sequentially randomly depending on the need of application.
6. Binary file does not required any special processing
7. Binary file also ends with end of file marker(EOF)
8. Example- 123 stored in 1 byte

Q. 4. Explain the utility of open() function.
Answer-
Open() function-
1. Before reading from or writing to file, you must first open file using built-in open() function.
2. Open() function creates a file object, which will be used to invoke methods associated with it.
3. Syntax for open() function-
Fileoobject=open(“filename”,”access_mode”)
4. Here filename is string value that specifies name of file that you want to access.
5. Access_mode indicates the mode in which file has to be opened.
i.e. read, write, append
6. The open function returns the file object.
7. This file object will be used to read write or perform any other operation on the file
8. File object works as file handle.
Example of opening file using open() function-
f=open(“file1.txt”,”w”)
f.write(“Keep learning python”)
f.close()
print(“Data written to te file”)

Q.5 What are different file access modes in which you can open a file?
Answer-
File Access Modes-
• Read(r, r+, rb, rb+)-read content from begining of file
1. r mode open text file for reading only
2. r+ mode open text file for read as well as write
3. rb mode open binary file for reading only
4. rb+ mode open bnary file for read as well as write
• Write (w, w+, wb, wb+)- write content from begining of file
1. w write mode, overwrite text file, create new if not exists.
2. W+ read and write mode, overwrite text file, create new file if not exists
3. wb write mode, overwrite binary file, create new if not exists.
4. wb+ read and write mode, overwrite binary file, create new file if not exists
• Append(a, a+, ab, ab+)-add content at the end begining of file
1. a append mode, add at end of text file, create new if not exists.
2. a+ append and read mode,add at end of text file, create new file if not exists
3. ab append mode, add at end of binary file, create new if not exists.
4. ab+ append and read mode, add at end of binary file, create new file if not exists.

Q.6 With the help of example explainany three attributes of file object.
Answer-
File Object Attributes-
1. Once the file successfully opened a file object is returned.
2. Using this file object you can easily access different types of information related to that file.
3. This information can be obtained by reading values of specific attributes of the file.
4. Following are the three file object attributes-
1. Fileobj.closed()- It returns True if file is closed ,otherwise returns False.
2. Fileobj.mode()- It returns file access mode in which file has been opened.
3. Fileobj.name()- It returns name of the file.

Example of file object attribute-

Written for

Institution
Course

Document information

Uploaded on
June 20, 2024
Number of pages
8
Written in
2023/2024
Type
Class notes
Professor(s)
Sid gunjal
Contains
All classes

Subjects

$3.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sidgunjal

Get to know the seller

Seller avatar
sidgunjal avcoe
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions