Best way to parse file into db-type layout?
Michael Hoffman
cam.ac.uk at mh391.invalid
Fri Apr 29 19:40:50 EDT 2005
John Machin wrote:
> [Michael Hoffman]:
>>John Machin wrote:
>>>[Michael Hoffman]:
>>>
>>>>for row in csv.reader(fileinput.input()):
>>>
>>>csv.reader requires that if the first arg is a file that it be opened
>>>in binary mode.
>>
>>fileinput.input() is not a file.
>
> Hair-splitter.
Is name-calling really necessary?
> It's an awk simulation and shouldn't be used for real-world data.
I don't see why not, so long as your data is text.
>>I have tested this code and it works fine for the provided example.
>
> Well I've got news for you: real-world data has embedded CRs, LFs and
> (worst of all) ^Zs often enough, and you won't find them mentioned in
> any documentation, nor find them in examples.
That's nice. Well I agree with you, if the OP is concerned about embedded
CRs, LFs and ^Zs in his data (and he is using Windows in the latter case),
then he *definitely* shouldn't use fileinput.
And otherwise, there's really no reason not to.
--
Michael Hoffman
More information about the Python-list
mailing list