Python Programming - Reading and Writing Files
Exercise : Reading and Writing Files - General Questions
- Reading and Writing Files - General Questions
36.
What is the purpose of the
os.path.isdir()
function?
Answer: Option
Explanation:
os.path.isdir()
checks if a path points to a directory.
37.
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 writing a list of dictionaries to a CSV file.
38.
What does the
file.tell()
method return?
Answer: Option
Explanation:
The
tell()
method returns the current position of the file cursor.
39.
How can you create a new directory named "my_directory"?
Answer: Option
Explanation:
The
os.mkdir()
function is used to create a new directory in Python.
40.
How can you read and print the lines containing numbers from a file named "text.txt"?
Answer: Option
Explanation:
Using
any()
and isdigit()
to filter and print lines containing numbers.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers