[Tutor] Beginner puzzle with unpacking argv
Lisi
lisi.reisz at gmail.com
Thu Jun 16 21:43:07 CEST 2011
On Thursday 16 June 2011 19:03:27 Joel Goldstick wrote:
> On Thu, Jun 16, 2011 at 1:10 PM, Lisi <lisi.reisz at gmail.com> wrote:
> > Copied and pasted:
> > >From text of Learn Python the Hard Way
> >
> > 1 from sys import argv
> > 2
> > 3 script, user_name = argv
> >
> > >From my script (typed, not copied and pasted, but copied and pasted from
> >
> > my
> > script to here):
> >
> > 1 from sys import argv
> > 2
> > 3 script, user_name = argv
> >
> > I have tried every permutation of white space I could think of that might
> > have
> > looked like the original, but I always get the same error:
> >
> > lisi at Tux:~/Python/LearnPythonTheHardWay$ python ex14.py
> > Traceback (most recent call last):
> > File "ex14.py", line 3, in <module>
> > script, user_name=argv
> > ValueError: need more than 1 value to unpack
> >
> > I haven't got past line 3 yet!! I know that you need the right number of
> > variables, but my script has got as many as the original - it's the same
> > as the original!
> when you run the program you are not giving it any arguments to read.
> argv[0] is the name of your script. But you are not providing a value for
> user_name to consume
>
> Try this:
>
> lisi at Tux:~/Python/LearnPythonTheHardWay$ python ex14.py Lisi
Thanks to all of you, guys. :-)) So it wasn't the script that was wrong, it
was the command I was giving. Doh!
It now runs fine as far as I have gone, so I can now finish typing the rest
of the script in. Hopefully without too many stupid mistakes. :-(
Lisi
More information about the Tutor
mailing list