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

Al Nevarez anevare2 at yahoo.com
Sun Jun 15 20:09:44 CEST 2008

What's the best way to preserve integers when loading a file into a list?

for example.. assume we have a tab delimited file that looks like this:
A	1
B	2
C	three

I have a line in my program to read that file in like this:

my_data=[line.strip().split('	') for line in file(data_file,'rU')]

the result in my_data is:
[['A', '1'], ['B','2'], ['C','three']]

But I need my_data to be like this:
[['A', 1], ['B',2], ['C','three']]

Needs to be automatic.. i.e. I'm not sure ahead of time, which if any value anywhere will be a string or an integer.



More information about the Baypiggies mailing list