Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
76.
What does the
file.encoding
attribute represent?
Answer: Option
Explanation:
file.encoding
represents the file's encoding.
77.
How can you read and print the lines containing the word "success" or "failure" from a log file named "logfile.txt"?
Answer: Option
Explanation:
Using
line.lower()
to make the comparison case-insensitive.
78.
What does the
file.fileno()
method return?
Answer: Option
Explanation:
file.fileno()
returns the file's file descriptor.
79.
How can you read and print the lines containing only alphabetic characters from a file named "textfile.txt"?
Answer: Option
Explanation:
Using
line.isalpha()
to check if the line contains only alphabetic characters.
80.
How can you copy the contents of a file named "source.txt" to another file named "destination.txt" while preserving the original file's metadata?
Answer: Option
Explanation:
Using
shutil.copy()
to copy the file contents and preserve metadata.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers