Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Formatted Input

Reply
Thread Tools

Formatted Input

 
 
Deep
Guest
Posts: n/a
 
      03-10-2007
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??

 
Reply With Quote
 
 
 
 
Frank
Guest
Posts: n/a
 
      03-10-2007
On Mar 10, 11:28 am, "Deep" <deepblue...@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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formatted input/output question dkk C Programming 2 04-12-2006 05:27 PM
Reporting formatted input operations that fail Jason Heyes C++ 0 06-24-2005 06:19 AM
J2SE 1.5 Formatted Input Question Matt Java 3 10-19-2004 08:07 AM
Formatted input interpretation TheDD C++ 7 05-15-2004 10:19 PM
From unformatted to formatted input TheDD C++ 4 05-13-2004 09:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57