Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
71.
What does the
file.mode
attribute represent?
Answer: Option
Explanation:
file.mode
represents the file's access mode.
72.
How can you read and print the lines containing the word "error" (case-insensitive) from a log file named "error.log"?
Answer: Option
Explanation:
Using
line.lower()
to make the comparison case-insensitive.
73.
What does the
file.isatty()
method check for?
Answer: Option
Explanation:
file.isatty()
checks if the file is connected to a terminal device.
74.
How can you write a list of tuples to a binary file named "data.bin"?
Answer: Option
Explanation:
Using
open()
in binary write mode and pickle.dumps()
to write a list of tuples to a binary file.
75.
How can you check if a file named "output.txt" is empty?
Answer: Option
Explanation:
Using
os.path.getsize()
to check if the file size is 0, indicating an empty file.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers