Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41933 > unrolled thread
| Started by | Dave Angel <davea@davea.name> |
|---|---|
| First post | 2013-03-26 13:55 -0400 |
| Last post | 2013-03-26 16:48 -0400 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: problem with sys import argv Dave Angel <davea@davea.name> - 2013-03-26 13:55 -0400
Re: problem with sys import argv Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-26 21:12 +0100
Re: problem with sys import argv Dave Angel <davea@davea.name> - 2013-03-26 16:48 -0400
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-03-26 13:55 -0400 |
| Subject | Re: problem with sys import argv |
| Message-ID | <mailman.3764.1364320531.2939.python-list@python.org> |
On 03/26/2013 01:26 PM, 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! > Since the script takes a mandatory argument, run it with one. python myscript.py Dave Better would be to change the script to check len(argv) for exactly 2, and tell the user how he should have run it. -- DaveA
[toc] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-03-26 21:12 +0100 |
| Message-ID | <7378582.EtEbenrJl9@PointedEars.de> |
| In reply to | #41933 |
Dave Angel wrote: > Since the script takes a mandatory argument, run it with one. > > python myscript.py Dave > > Better would be to change the script to check len(argv) for exactly 2, > and tell the user how he should have run it. I would use argparse.ArgumentParser instead. <http://docs.python.org/dev/library/argparse.html> -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-03-26 16:48 -0400 |
| Message-ID | <mailman.3773.1364330936.2939.python-list@python.org> |
| In reply to | #41946 |
On 03/26/2013 04:12 PM, Thomas 'PointedEars' Lahn wrote: > Dave Angel wrote: > >> Since the script takes a mandatory argument, run it with one. >> >> python myscript.py Dave >> >> Better would be to change the script to check len(argv) for exactly 2, >> and tell the user how he should have run it. > > I would use argparse.ArgumentParser instead. > > <http://docs.python.org/dev/library/argparse.html> > As would I. But that would be out of proportion of the rest of the code, and therefore presumably beyond the needs or interest of the OP. -- DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web