Formatted Input

Discussion in 'Python' started by Deep, Mar 10, 2007.

  1. Deep

    Deep Guest

    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??
     
    Deep, Mar 10, 2007
    #1
    1. Advertising

  2. Deep

    Frank Guest

    On Mar 10, 11:28 am, "Deep" <> 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).

    Hope this helps,

    Frank
     
    Frank, Mar 10, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    455
    Eric Reitmaier
    Oct 19, 2004
  2. TheDD
    Replies:
    4
    Views:
    532
    John Harrison
    May 13, 2004
  3. TheDD
    Replies:
    7
    Views:
    402
    TheDD
    May 15, 2004
  4. dkk

    formatted input/output question

    dkk, Apr 10, 2006, in forum: C Programming
    Replies:
    2
    Views:
    335
    Herbert Rosenau
    Apr 12, 2006
  5. Jason Heyes
    Replies:
    0
    Views:
    279
    Jason Heyes
    Jun 24, 2005
Loading...

Share This Page