[Tutor] Prevent "Coder's Remorse"?

Kent Johnson kent37 at tds.net
Thu Sep 29 11:54:39 CEST 2005

Ron Phillips wrote:
> Maybe I should explain why I thought I wanted this object. I am trying
> to read, edit, and write shapefiles (actually, a shapefile is a
> collection of 3-6 files having the same filename, but different
> extensions. It's a legacy format that still gets a lot of use in
> geography.)
> One of the constituent files in a shapefile is a variant of Xbase,
> which knows nothing  about NULL, so I have to provide some value in
> every column for every record when I write them. I thought that having a
> data structure that enforces a common set of "fields", the application
> would be more robust when it's being edited. (Prevent me from deleting
> an item for one record and not others, or adding a field to a record
> without adding at least some default value to all the others.)
> I just thought about it, but a CSV file has kind of the same problem.

I think I would try the same solution used by csv.DictWriter - use a writer object that has knowledge of the required fields and a default value. This assumes that at the time of writing you know what the required fields are, which seems reasonable but without knowing more about your app I can't be sure. Then the writer fills in the necessary default values as it writes the data.


More information about the Tutor mailing list