[Baypiggies] Preserving integers when loading a file into a list

Brent Pedersen bpederse at gmail.com
Sun Jun 15 22:46:18 CEST 2008

On Sun, Jun 15, 2008 at 12:31 PM, Jason Culverhouse
<jason at mischievous.org> wrote:
> not x.isdigit() and x or int(x) is going to fail for empty string... ''
>        not False and '' or int('') <-value error since
> You could combine Adam's try_int_convert
> import csv
> import functools
> import sys
> i = functools.partial(map, try_int_convert) # maybe  convert a list to int
> t = functools.partial(tuple) # convert to tuple, not sure if you need the in
> tuples
> #Read a TSV file from stdin and convert
> [t(i(line)) for line in csv.reader(sys.stdin, dialect='excel-tab')]
> Jason

good point. out of curiosity, how is t = functools.partial(tuple),
then using t() different from using tuple() directly?

More information about the Baypiggies mailing list