CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

File Handling (2 Marks Questions)

  1. Differentiate between file modes rb+  and w+  with respect to Python.
  2. Write a method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with an alphabet ‘P’.
  3. When do you think text files should be preferred over binary files?
  4. Write the difference between relative and absolute path?
  5. Write the short note on the following?
    • docstrings
    • why a package is attached to site-package folder of python installation?
  6. Write a method in python to write multiple line of text contents into a text file mylife.txt line.
  7. What is the output of the following code:
    File (myOutFile.txt) contents:
    You may write me down in history
    With your bitter, twisted lies, 
    You may trod me in the very dirt
    But still, like dust, I'll rise. 

  8. Write a program to count and display the number of uppercase letters present in text file’s (“Article.txt”) first and last line.
  9. What is the use of flush() Function? Explain using suitable examples?
  10. Write a function stats() that accepts a filename and reports the file's longest line.
  11. Write a statement in Python to perform the following operations :
    1. To open a text file “Book.txt” in read mode
    2. To open a binary file “Book.dat” in write mode
  12. Write a program to count the words “to” and “the” present in a text file “Poem.txt”.

No comments:

Post a Comment