Formatted Input

D

Deep

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??
 
F

Frank

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).

Hope this helps,

Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top