Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'float': 0.07; 'sys': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variable,': 0.09; 'python': 0.11; 'command-line': 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; 'subject:variable': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; "i'd": 0.34; 'could': 0.34; 'etc.)': 0.35; 'example,': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'conversion': 0.61; 'numbers': 0.61; 'simple': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'sum': 0.64; 'equals': 0.68 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 18:46:40 +0100 Organization: None References: 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392140807 news.xs4all.nl 2886 [2001:888:2000:d::a6]:47062 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65933 luke.geelen@gmail.com wrote: > i'd like to know how to set up a flag to change a variable, > for example, i want a simple script to combine 2 numbers, > > > sum = num + another_num > print "Now the sum of the numbers equals : ", sum > > how could i make it so that if i type python ./script.py 21 41 > that i get the sum of 21 and 41 ? You seem to be looking for sys.argv which contains the script name and the command-line arguments. $ cat script.py import sys a = int(sys.argv[1]) b = int(sys.argv[2]) print a, "+", b, "=", a + b $ python script.py 21 41 21 + 41 = 62 The conversion to int (or float etc.) is necessary because in python >>> "21" + "41" '2141'