Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
66.
What is the purpose of the
file.readable()
method?
Answer: Option
Explanation:
file.readable()
checks if the file is open for reading.
67.
How can you read and print the lines containing the word "Python" in a case-insensitive manner from a file named "code.txt"?
Answer: Option
Explanation:
Using
line.lower()
to make the comparison case-insensitive.
68.
What does the
shutil.copy2()
function do?
Answer: Option
Explanation:
shutil.copy2()
copies a file and preserves its metadata.
69.
How can you read and print the lines containing at least three digits from a file named "text.txt"?
Answer: Option
Explanation:
Using
sum(c.isdigit() for c in line)
to count digits in each line.
70.
How can you write a list of dictionaries to a CSV file named "data.csv"?
Answer: Option
Explanation:
Using a context manager to open the file and
csv.writer()
to write a list of dictionaries to a CSV file.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers