Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41933

Re: problem with sys import argv

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"""': 0.07; 'error:': 0.07; 'sys': 0.07; 'valueerror:': 0.09; 'python': 0.11; 'wrote': 0.14; '"i\'d': 0.16; '%r.': 0.16; "%s'": 0.16; '%s,': 0.16; 'argument,': 0.16; 'received:74.208.4.195': 0.16; 'script,': 0.16; 'skip:" 70': 0.16; 'subject:import': 0.16; 'unpack': 0.16; 'wrote:': 0.18; 'community,': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'subject:problem': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'username': 0.31; 'file': 0.32; 'thanks!': 0.32; 'run': 0.32; '(most': 0.33; 'computer.': 0.33; 'subject:with': 0.35; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'dave': 0.60; 'is.': 0.60; 'tell': 0.60; 'kind': 0.63; 'more': 0.64; 'prompt': 0.68; 'received:74.208': 0.68; 'lives': 0.74; 'liking': 0.84
Date Tue, 26 Mar 2013 13:55:07 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4
MIME-Version 1.0
To python-list@python.org
Subject Re: problem with sys import argv
References <A33EC90F-DEC4-424D-BDBF-68165669A336@icloud.com>
In-Reply-To <A33EC90F-DEC4-424D-BDBF-68165669A336@icloud.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:xhq7dIj6341AiF7DdcVWMUPCZib+HGRafbXMmPugvus 7fsZcSXWVz9WEZGs7/oV+d3r7qX9z7qWTuIPRrEo5Aa0yADbZy DRxmoUr+G3CPp5V14KxiKE9yVbWFFpjojcu1AKGC0yNKrPzNAc UJ0uehMUJ0HIF02raAmzAMAxlh0VaWYEERIRo5ZRx6GBENiXP2 TWtgU1KIlRjFJZu9NtC8uv1DI5gnfAjgukVnMHkuDCXALXkzel 2lznizmen16+q3D43aaLL3/wU8v549QvyhUsZyFFifrLMUAt0y 23Kl0N6Z5em7jRpxK7i4hUbsHV/AVqWByCqFCp7q9zoezhTUg= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3764.1364320531.2939.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364320531 news.xs4all.nl 6920 [2001:888:2000:d::a6]:60960
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41933

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web