Formatted Input

Frank supervau at gmail.com
Sat Mar 10 16:23:18 EST 2007


On Mar 10, 11:28 am, "Deep" <deepblue... at gmail.com> wrote:
> Hi all,
> I am a newbie to python
> I have an input of form
> <one number> space <another number>
> ie.
> 4 3
> how can i assign this to my variables??

Hi,

you could use:

aux = f.readline()  # read a line from your input file
new_aux = string.split(aux, ' ') # you can use also other separaters,
e.g., \t, or '  more than one space', or...
L = len(new_aux) # number of values
Remark:
the elements in new_aux are string, that means you have to convert
them to numbers by,, e.g., int(row[i]).

Hope this helps,

Frank





More information about the Python-list mailing list