Re: problem with sys import argv

Discussion in 'Python' started by Mark Lawrence, Mar 26, 2013.

  1. On 26/03/2013 17:26, leonardo selmi wrote:
    > hi python community,
    >
    > i wrote the following programm:
    >
    > from sys import argv
    >
    > script, userName = argv
    > prompt = '> '
    >
    > print 'hi %s, i am the %s script' % (userName, script)
    > print "i'd like to ask you a few questions."
    > print 'do you like me %s' % userName
    > likes = raw_input(prompt)
    >
    > print "where do you live %s?" % userName
    > lives = raw_input(prompt)
    >
    > print 'what kind of computer do you have?'
    > computer = raw_input(prompt)
    >
    > print """
    > alright so you said %r about liking me.
    > you live in %r. not sure where that is.
    > and you have a %r computer. nice
    > """ % (likes, lives, computer)
    >
    > and i got the following error: Traceback (most recent call last):
    > File "/var/folders/89/84z7tw3d3rv39gny3n2p963m0000gn/T/pythonInTerm.GUF6PWCM", line 3, in <module>
    > script, userName = argv
    > ValueError: need more than 1 value to unpack
    >
    > what can i do?
    >
    > thanks!
    >


    Write some error handling to allow for the script being run without the
    user name.

    --
    If you're using GoogleCrap™ please read this
    http://wiki.python.org/moin/GoogleGroupsPython.

    Mark Lawrence
     
    Mark Lawrence, Mar 26, 2013
    #1
    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. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,658
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    6,048
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,696
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    968
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. Dave Angel

    Re: problem with sys import argv

    Dave Angel, Mar 26, 2013, in forum: Python
    Replies:
    2
    Views:
    129
    Dave Angel
    Mar 26, 2013
Loading...

Share This Page