I usually use the following Python code to read lines from a file :
f = open('./my.csv', 'r')
for line in f:
print line
But how about if the file is line delimited by "\0" (not "\n") ? Is there a Python module that could handle this ?
Thanks for any advice.
If your file is small enough that you can read it all into memory you can use split:
Otherwise you might want to try this recipe from the discussion about this feature request:
I also noticed your file has a "csv" extension. There is a CSV module built into Python (import csv). There is an attribute called
Dialect.lineterminator
however it is currently not implemented in the reader:I have modified Mark Byers's suggestion so that we could READLINE file with NUL delimited lines in Python. This approach reads a potentially large file line by line and should be more memory efficient. Here is the Python code (with comments) :
Hope it helps.