How can a single line of user input be converted into multiple variables ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pwilliams
    New Member
    • Jul 2010
    • 21

    How can a single line of user input be converted into multiple variables ?

    For example:
    info= input('Enter name address and telephone number\n')
    I have tried declaring variables in advance ie.
    var1 = " " var2 = " " var3 = " " but to no avail. Can you please help ?
    Thanks in anticipation.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    If you are using Python 2.x, use raw_input(). To accomplish your task, the entered data must be formatted for parsing. Delimiting the data with commas will do nicely. Example, entering "Bill,101 Main St.,(888) 000-000":
    Code:
    >>> n,a,t = raw_input("Enter Name, Address, Telephone #").split(',')
    >>> n
    'Bill'
    >>> a
    '101 Main St.'
    >>> t
    '(888) 000-000'
    >>>

    Comment

    • pwilliams
      New Member
      • Jul 2010
      • 21

      #3
      How can a single line of user input be converted into multiple variables ?

      Many thanks for such a rapid solution ; the online articles
      make no reference ,to the best of my knowledge, to multiple variables for input / raw_input.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        EasyGUI is a simple solution if you are entering parameters from the command line. If you are calling the program from another program and supplying parameters, then it obviously won't work. http://easygui.sourceforge.net/

        Comment

        Working...