[Csv] Re: First Cut at CSV PEP

Cliff Wells LogiplexSoftware at earthlink.net
Thu Jan 30 23:34:32 CET 2003


On Thu, 2003-01-30 at 13:45, Cliff Wells wrote:
> On Thu, 2003-01-30 at 13:02, Skip Montanaro wrote:
> >     Cliff> Export is a slightly different story.  I do think None should be
> >     Cliff> mapped to '' on export since that is the only reasonable value
> >     Cliff> for it, and there are enough existing modules that use None to
> >     Cliff> represent an empty value that this would be a reasonable thing
> >     Cliff> for us to handle.
> > 
> > How is a database (that was Dave's use case) supposed to distinguish '' as
> > SQL NULL vs '' as an empty string though?  This is the sort of thing that
> > bothers me about mapping None to ''.
> 
> The database not being able to distinguish '' from SQL NULL is inherent
> in the file format.  CSV files have no concept of '' vs None vs NULL. 
> There is only ,, or ,"", which I think should be considered the same
> (because the same data [or lack of] can be expressed either way by
> tweaking the quote settings).
> 
> If we don't want them to be considered the same, then we need YAO to
> specify whether to interpret them differently.  

Hm.  Something has occurred to me.  How about treating None as a true
null value.  That is, we never quote it. So, even if alwaysquote == true

[1,2,3,'',None] 

would get exported as 

'1','2','3','',

That way the difference between the two is saved in the CSV file. 
Obviously not all programs would be able to take advantage of this
implicit information, but it seems likely some would (does Excel
differentiate between an empty string and a null value?  It wouldn't
surprise me to discover that the '' becomes an empty *character* cell
and the null value is simply ignored).

Clearly this behavior is not desirable in all circumstances.  However,
the workaround in any case is to not have None values in the data to be
exported <wink>.  This punts any possible issues with it back into
user-space.

The only problem I have with this is that the behavior sort of
implicit.  It saves us a couple of options but it puts the settings in
the data which I am not sure is a good idea.

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308



More information about the Csv mailing list