[Tutor] Beginner puzzle with unpacking argv

Joel Goldstick joel.goldstick at gmail.com
Thu Jun 16 20:03:27 CEST 2011


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!
>
> Help!
>
> Lisi
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

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





-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110616/d4e5cb6a/attachment.html>


More information about the Tutor mailing list