newbe how to read in a string? the solution

William Famy william.famy at noos.fr
Fri Mar 23 10:17:21 EST 2001


Thanks for you answer.

This a sumary of the answer i receive. 
_________________________________________________
import string
     d,n1,n2,n3 = string.split(a, ",")
     n1 = float(n1)
     n2 = float(n2)
     n3 = float(n3)
 
 If the list of numbers is of variable length, this might be cool:
 
     import string
     seq = string.split(a, ",")
     for i in range(1, len(seq)): # this skips the 0 index,
         seq[i] = float(seq)      # which needs to stay a string.
_______________________________________________
One possibility:

import string

a='2000/12/28,24.3,87.1,65.4'
b = string.split(a, ',')

Then b[2] is 87.1,written as string: str(b[2])
_________________________________________________

strFields = a.split(",")
thirdField = strFields[2]
_________________________________________________



-- 
 			     \\\|///
                           \\  - -  //
                            (  @ @  )
+-------------------------oOOo-(_)-oOOo-------------------------+
|  Famy William  36 avenue des barattes  74000 Annecy  France   |
|  email:william.famy at noos.fr william.famy at mail-enseignant.com  |
+---------------------------------Oooo--------------------------+
                           oooO   (   )
                          (   )    ) /
                           \ (    (_/
                            \_)



More information about the Python-list mailing list