[Tutor] assigning types(?) to list elements
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 14 Oct 2002 17:20:46 +0100
WARNING: Untested code!
> for each_line in file_handle.readlines() :
> each_line = each_line.rstrip() # strip off carriage return
> temp1, temp2, temp3, temp4, temp5, temp6 =
> string.split(each_line)
vals = string.split(each_line)
types = [float,int,float,float]
for i in range(2,len(types)):
vals[i] = types[i](vals[i]) # convert types
temp1,temp2,temp3,temp4,temp5 = vals # assign to vars
Not wonderful, I suspect there is a better pythonic way to do it,
but it is at least extensible...
Is that any better?
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld