[Csv] CSV interface question
Dave Cole
djc at object-craft.com.au
Thu Jan 30 00:49:44 CET 2003
>>>>> "Andrew" == Andrew McNamara <andrewm at object-craft.com.au> writes:
Andrew> csv.reader(fileobj, csv.dialect.excel)
>>
Andrew> Thoughts?
>>
Dave> Is there a downside to this? I can't see one immediately.
>> With the dialect concept all we are talking about is a collection
>> of parameter settings. Encapsulating that as subclasses seems like
>> it hides the data-oriented nature behind the facade of source code.
Andrew> It has the virtue that sub-classing can be used to represent
Andrew> related variants. So, excel-tab might be:
Andrew> class excel-tab(excel):
Andrew> delimiter = '\t'
Not sure the python interpreter will like that class name :-)
Andrew> This could also be useful for users of the module:
Andrew> class funky(excel):
Andrew> quotes = "'"
Andrew> Essentially we'd be using classes as glorified dictionaries
Andrew> with cascading values.
I would prefer attribute only flat objects. The alternative would
have us traversing inheritance trees to extract class dictionaries.
class dialect:
def __init__(self, delimiter=',', ...):
self.delimiter = delimiter
:
>>> funky = csv.copy_dialect('excel')
>>> funky.quotes = "'"
Not as nice as subclassing, but probably good enough.
- Dave
--
http://www.object-craft.com.au
More information about the Csv
mailing list