Python Data File Handling

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By MariamaThomas201
M
MariamaThomas201
Community Contributor
Quizzes Created: 1 | Total Attempts: 151
Questions: 12 | Attempts: 151

SettingsSettingsSettings
Python Data File Handling - Quiz


Questions and Answers
  • 1. 

    Which file content is human readable format ?

    • A.

      Binary File

    • B.

      Text File

    Correct Answer
    B. Text File
    Explanation
    A text file is considered to be in human-readable format because it contains plain text that can be easily understood and interpreted by humans. Unlike a binary file, which contains data in a format that is not easily readable by humans, a text file can be opened and read using a simple text editor or word processor. The content of a text file is typically organized in lines and can include characters, numbers, symbols, and other readable text.

    Rate this question:

  • 2. 

    When you open a  file  in a+ mode file pointer will be at

    • A.

      Beginning of File

    • B.

      End of File

    Correct Answer
    B. End of File
    Explanation
    When you open a file in a+ mode, the file pointer will be at the end of the file. This means that any data written to the file will be appended to the existing content. If there is no existing content in the file, the file pointer will still be at the end of the file, ready for data to be written.

    Rate this question:

  • 3. 

    In which mode  all the files are opened in by default.

    • A.

      Read mode

    • B.

      Append mode

    • C.

      Write mode

    Correct Answer
    A. Read mode
    Explanation
    By default, when files are opened, they are opened in read mode. This means that the file can only be read and its contents can be accessed, but no modifications can be made to the file. In read mode, the file pointer is positioned at the beginning of the file, allowing the user to read the file from the start.

    Rate this question:

  • 4. 

    Name the module should be imported to  operate with binary file .

    • A.

      Sys

    • B.

      Os

    • C.

      Pickle

    Correct Answer
    C. Pickle
    Explanation
    The correct answer is pickle. The pickle module in Python provides functions for serializing and deserializing objects. It is used to convert complex objects into a byte stream, which can be stored or transmitted, and then convert it back into the original object. This module is commonly used for working with binary files, as it allows for easy storage and retrieval of data in a compact format.

    Rate this question:

  • 5. 

    Given the following code …. File=open(“Mydata”,”a”) File.close()                              What type of file is mydata?

    • A.

      Binary File

    • B.

      Text File

    Correct Answer
    B. Text File
    Explanation
    The file "Mydata" is a text file because it is opened with the mode "a" which stands for append. This mode is typically used for writing text to a file.

    Rate this question:

  • 6. 

    Name the method used to know the current position of the file pointer

    • A.

      Seek()

    • B.

      Tell()

    Correct Answer
    B. Tell()
    Explanation
    The method used to know the current position of the file pointer is "tell()". This method returns the current position of the file pointer, which indicates the next byte that will be read or written. By using this method, we can keep track of the current position within a file and perform operations accordingly.

    Rate this question:

  • 7. 

    Which module is required to use built in function dump()?

    • A.

      Math

    • B.

      Flush

    • C.

      Pickle

    Correct Answer
    C. Pickle
    Explanation
    The module required to use the built-in function dump() is pickle. The dump() function is used to serialize and save Python objects into a file. The pickle module provides the necessary functionality to perform this serialization process.

    Rate this question:

  • 8. 

    Read the following code : F1=open(“main.txt”,”w”) F1.write(“BYE”) print(F1.tell()) if the file contains  “GOOD”  before execution . What will be display after the execution of the above code:

    • A.

      7

    • B.

      8

    • C.

      9

    • D.

      6

    Correct Answer
    A. 7
    Explanation
    The code opens a file named "main.txt" in write mode and assigns it to the variable F1. It then writes the string "BYE" to the file. The print(F1.tell()) statement returns the current position of the file pointer, which is the number of characters written to the file so far. Since "BYE" has 3 characters, the file pointer is at position 3. Therefore, the answer is 7.

    Rate this question:

  • 9. 

    The  readlines() method return -----------------

    • A.

      List of integers

    • B.

      List of Lines

    • C.

      Single line

    Correct Answer
    B. List of Lines
    Explanation
    The readlines() method in Python returns a list of lines from a file. Each line is represented as a string element in the list. Therefore, the correct answer is "List of Lines".

    Rate this question:

  • 10. 

    From the following which file  mode is used to read from a binary file.

    • A.

      R

    • B.

      R+

    • C.

      Rb

    Correct Answer
    C. Rb
    Explanation
    The correct answer is "rb". In file modes, "r" is used to read from a file, but when dealing with binary files, the "b" is added to specify that the file is in binary format. This mode allows for reading binary data from the file.

    Rate this question:

  • 11. 

    Current working directory / folder  can be determined by using ------------------ method .

    • A.

      Getdir()

    • B.

      Getcwd()  

    • C.

      Dirget()

    Correct Answer
    B. Getcwd()  
    Explanation
    The correct answer is "getcwd()". This method is used to determine the current working directory or folder.

    Rate this question:

  • 12. 

    Opening a file in append mode erases the previous data

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Opening a file in append mode does not erase the previous data. Instead, it allows new data to be added to the end of the file without overwriting or deleting the existing content. This is useful when we want to add new information to a file without losing the existing data.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 12, 2020
    Quiz Created by
    MariamaThomas201
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.