[Csv] confused about wrapping readers and writers

Andrew McNamara andrewm at object-craft.com.au
Mon Feb 10 09:47:24 CET 2003


>>    >>> dir(rdr)
>>    ['delimiter', 'doublequote', 'escapechar', 'lineterminator',
>>    'quotechar', 'quoting', 'skipinitialspace', 'strict'] 
>
>For reasons that I haven't looked into, dir() is not finding methods
>on the objects we're creating - I suspect this is a hang-over from the
>type/class unification (i.e., we need to exercise an extended API to
>get our methods exposted).

We were using "old-style" getattr/setattr - a day of pawing over python
internals showed how to use the new interfaces, so __iter__ and next
are now exposed the way they should be, and dir(...) lists all methods.

I also changed the Dialect structure into a fully fledged python type -
this was something I'd been considering for a while, but had assumed
there would be too much of a performance impact. Turns out there wasn't,
and it's made the code cleaner.

Note that the reader and writer objects no longer have attributes
corresponding to the individual settings - instead, they have a "dialect"
attribute, which contains the settings. It would be a relatively trivial
matter to proxy getattr/setattr requests from reader/writer to the
dialect instance - I can do this if people think it's worthwhile.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


More information about the Csv mailing list