Nov-05-2019, 09:04 AM
While choosing between different options while reading data from text files I have found useful following those loose rules:
- if data in file is 'table with header' -> use csv.DictReader (maps automagically)
- if data in file is 'table without header' -> provide headers and use csv.DictReader
- if data in file is not structured and has quotes '"' and/or other ('weird') formatting -> use csv.reader (handles these automagically)
- if data on rows is not structured -> iterate over fileobject rows directly and do your own magic
... and then there is pandas :-).
No 'one obvious way' here. Use tools you comfortable with.
- if data in file is 'table with header' -> use csv.DictReader (maps automagically)
- if data in file is 'table without header' -> provide headers and use csv.DictReader
- if data in file is not structured and has quotes '"' and/or other ('weird') formatting -> use csv.reader (handles these automagically)
- if data on rows is not structured -> iterate over fileobject rows directly and do your own magic
... and then there is pandas :-).
No 'one obvious way' here. Use tools you comfortable with.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.