[Csv] dict argument to writer.writerow
Andrew McNamara
andrewm at object-craft.com.au
Thu Feb 6 05:56:11 CET 2003
I don't think this belongs in writer.writerow - I'd suggest it belongs
in the as yet unwritten csv.util module. The problem is that it's going
to have an appreciable impact on the normal case of writing a tuple.
There's no need to have the code auto-detect a dictionary - the user
of the module will know before-hand whether they have a dict or tuple,
and can use the appropriate layer.
# if fields is a dict, we need a valid fieldnames list
# if self.fieldnames is None we'll get a TypeError in the for stmt
# if fields is not a dict we'll get an AttributeError on .get()
try:
flist = []
for k in self.fieldnames:
flist.append(fields.get(k, ""))
fields = flist
except (TypeError, AttributeError):
pass
--
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
More information about the Csv
mailing list