Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'elif': 0.05; 'debugging': 0.07; 'sys': 0.07; 'arguments': 0.09; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'valueerror:': 0.09; 'python': 0.11; '"*"': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'sign,': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'trying': 0.19; "skip:' 30": 0.19; 'import': 0.22; 'shell': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'directory.': 0.24; 'script.': 0.24; 'fine': 0.24; 'purposes': 0.26; 'header:X-Complaints-To:1': 0.27; "i'm": 0.30; 'file': 0.32; '(most': 0.33; 'skip:# 10': 0.33; 'something': 0.35; 'but': 0.35; 'two': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'email addr:gmail.com': 0.63; 'sum': 0.64; 'here': 0.66; 'invalid': 0.68; 'url:%1': 0.72; 'touch': 0.74; "'2',": 0.84; '10:': 0.84; 'url:tl': 0.84; 'url:translate': 0.84; 'luck': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Flag control variable Date: Tue, 11 Feb 2014 19:51:40 +0100 Organization: None References: <5019eb5d-ebda-4417-ab2d-9a58afcdd186@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd982e.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392144694 news.xs4all.nl 2934 [2001:888:2000:d::a6]:51341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65942 luke.geelen@gmail.com wrote: > well i'm trying something else but no luck : > > #!bin/bash/python Hm. > import sys > import os For debugging purposes put the line print sys.argv here to see what arguments are passed to the script. When you type $ python script.py 2 * 2 in the shell the "*" sign is replaced with all items in the current directory. To avoid that you have to escape, i. e. prepend a backslash: $ python script.py 2 \* 2 To illustrate: $ touch one two three $ ls one three two $ python -c 'import sys; print sys.argv' 2 + 2 ['-c', '2', '+', '2'] $ python -c 'import sys; print sys.argv' 2 * 2 ['-c', '2', 'one', 'three', 'two', '2'] $ python -c 'import sys; print sys.argv' 2 \* 2 ['-c', '2', '*', '2'] > a = int(sys.argv[1]) > sign = (sys.argv[2]) > b = int(sys.argv[3]) > > if sign == '+': > sum = a + b > print a, sign, b, "=", a + b > command1 = "sudo mpg321 > 'http://translate.google.com/translate_tts?tl=en&q=%s_plus%s_equals%s'" > % (a, b, sum) os.system (command1) > > elif sign == "*": > sum = a * b > print a, sign, b, "=", a * b > command1 = "sudo mpg321 > 'http://translate.google.com/translate_tts?tl=en&q=%s_times%s_equals%s'" > % (a, b, sum) > > when using * i get > > Traceback (most recent call last): > File "./math+.py", line 6, in > b = int(sys.argv[3]) > ValueError: invalid literal for int() with base 10: > 'Adafruit-Raspberry-Pi-Python-Code' > > i don't understand why b is a problem, it works fine with +