Professional Documents
Culture Documents
Ans Key Ut 3pdf
Ans Key Ut 3pdf
CSV: Reading and writing data in CSV format may be slower and less efficient than binary files because
data conversion (between text and numeric values) is often required.
Binary File: Binary files are more efficient for reading and writing data since they store it in a format that
can be directly used by the computer's memory.
2. seek(offset, whence): The seek() function is used to change the current file position (cursor) within a
file. It takes two arguments:
offset: This is the number of bytes to move the file cursor. A positive value moves the cursor forward,
and a negative value moves it backward.
whence (optional, defaults to 0): It specifies the reference point for the offset.
tell() Function:
tell(): The tell() function is used to retrieve the current file position (cursor) within the file. It returns an
integer representing the current offset in bytes from the beginning of the file.
3. To count the number of occurrences of the word "is" in a text file, you can use the following Python
code:
count = 0
words = line.split()
count += 1
4. import csv
csv_file = "example.csv"
writer = csv.writer(file)
writer.writerows(data)
5. "w" Mode:
When a file is opened in "w" mode, it is created if it does not exist, and if it does exist, its content is
truncated, meaning it is cleared.
a" Mode:
When a file is opened in "a" mode, it is created if it does not exist, but if it does exist, the file's content is
not cleared. Instead, data is appended to the end of the file.
"r+" Mode:
When a file is opened in "r+" mode, you can both read from and write to the file.
A CSV reader is a tool or module in Python that allows you to read data from CSV files efficiently.