[Python-ideas] CSV api with conversion

Bruce Leban bruce at leapyear.org
Thu Apr 15 02:20:52 CEST 2010


Sure I could do that. I just this think if you're making a convenience
function like this you should strive to make it more convenient.  :-)

--- Bruce
(via android)

On Apr 14, 2010 4:03 PM, "MRAB" <python at mrabarnett.plus.com> wrote:

Bruce Leban wrote:
>
> If you do this, you'll probably want to support mapping empty values. That
is...
The actual values read from the CSV file are strings and you're passing
them to functions:

   int("1"), str("")
   int(""), str("2")

If you want it to return a default value instead of raising an exception
on an empty field then you should pass a conversion function which does
that, for example:

   def int_or_none(field):
       if field.strip():
          return int(field)
       else:
          return None

> --- Bruce
> > http://www.vroospeak.com
> >
> >
>
> > On Mon, Apr 12, 2010 at 3:24 AM, Éric Araujo <merwok at netwok.org <mailto:
> merwok at netwok.org>> wrote:...
>    Python-ideas at python.org <mailto:Python-ideas at python.org>
>
>
> >    http://mail.python.org/mailman/listinfo/python-ideas
> >
> >
> >
> ------------------------------------------------------------------------
>
>
> >
> > _______________________________________________
> > Python-ideas mailing list
> > Python-ideas at pyth...
>


_______________________________________________
Python-ideas mailing list
Python-ideas at python.org
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100414/b1ed0137/attachment.html>


More information about the Python-ideas mailing list