Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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; 'operator': 0.03; 'syntax': 0.04; 'arguments': 0.09; 'cc:addr:python-list': 0.11; '"-":': 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'operation.': 0.16; 'subject:variable': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; 'header:In-Reply- To:1': 0.27; '"",': 0.31; 'easy,': 0.31; 'file': 0.32; 'actual': 0.34; 'problem': 0.35; 'something': 0.35; 'operations': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'skip:p 20': 0.39; 'email addr:gmail.com': 0.63; 'to:addr:gmail.com': 0.65; 'invalid': 0.68; 'received:50.22': 0.84 Date: Tue, 11 Feb 2014 12:32:54 -0600 From: Tim Chase To: luke.geelen@gmail.com Subject: Re: Flag control variable In-Reply-To: <0938f7a5-702f-48f7-a8ef-cd0a2fb198df@googlegroups.com> References: <0938f7a5-702f-48f7-a8ef-cd0a2fb198df@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392143537 news.xs4all.nl 2839 [2001:888:2000:d::a6]:40879 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65939 On 2014-02-11 10:16, luke.geelen@gmail.com wrote: > when expandig the script to multiple calcs i got a problem > >>> a = 32 > >>> c = 51 > >>> sign = * > > File "", line 1 > sign = * > ^ > SyntaxError: invalid syntax > > is there a way of adding * without quoting marks, because if you do > it just soms the arguments -- You want to store the actual operation. The "operator" module makes this fairly easy, so you can do something like import operator as o operations = { "*": o.mul, "+": o.add, "/": o.div, "-": o.sub, } a = 32 c = 51 operation = operations["*"] print(operation(a,c)) -tkc