PEP 305 - CSV File API

Carlos Ribeiro cribeiro at mail.inet.com.br
Tue Feb 4 02:10:43 CET 2003


On Monday 03 February 2003 10:15 am, John Machin wrote:
> Carlos Ribeiro <cribeiro at mail.inet.com.br> wrote in message
> news:<mailman.1044231844.17120.python-list at python.org>...
>
> > And last, but not least, the CSV library has to take into account other
> > things that happen to be problematic, and that are locale-related:
> >
> > - reading dates from a CSV file
>
> Certainly dates are a problem in that they are presented differently
> to users in different locales, and most people don't bother to use the
> ISO standard when writing to a file --- however, in what way is
> reading dates from a CSV-format file any different to reading them
> from any other format?

Although CSV files are not required to be tabular, most CSV files are: each 
line represents a single record (one 'row' of the table), and each record is 
composed of a fixed number of fields that can be understood as its 'columns'. 
Each column has data of a single type. In this situation, it would be useful 
to be able to associate not only the column name, but also the default data 
type used.

--> When reading CSV data, the default data type would be useful to 
differentiate 'date' columns from 'string' columns. Although automatic 
detection of date columns can be implemented, an option to 'force' 
recognition of dates in secific formats would be useful (for instance, 
automatic detection can't tell whether a date is in m/d/y and d/m/y format in 
lots of cases).

--> More important, when *writing* CSV data, it is important to know the 
correct column type and data format. Being able to correctly format all 
locale-dependent data is important when you have to export information to 
applications such as MS Excel, which *does* depend on this when importing 
data from CSV files.

Of course, one could say that better support for formatting dates is just 
'syntactic sugar'. That's right, but it does not make it any less useful, 
specially if you consider the type of application that CSV files are used for 
- importing and exporting data from different programs and even different 
OSs.


p.s. BTW, MS Excel also chokes when importing numbers with the 'wrong' format 
- it imports all such numbers as strings.


Carlos Ribeiro
cribeiro at mail.inet.com.br





More information about the Python-list mailing list