Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.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; 'python,': 0.02; 'subject:Python': 0.06; 'compiler': 0.07; 'assuming': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'python': 0.11; '"idle': 0.16; 'angle': 0.16; 'equality.': 0.16; 'fine.': 0.16; 'finney': 0.16; 'ought': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:variable': 0.16; 'symbols': 0.16; 'typo': 0.16; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'errors.': 0.24; "shouldn't": 0.24; 'compare': 0.26; 'define': 0.26; 'this:': 0.26; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'compared': 0.30; 'then.': 0.30; "d'aprano": 0.31; 'everywhere': 0.31; 'steven': 0.31; 'symbolic': 0.31; 'values.': 0.31; 'writes:': 0.31; 'yes.': 0.31; 'quite': 0.32; 'could': 0.34; 'problem': 0.35; 'anybody': 0.35; 'test': 0.35; 'but': 0.35; 'false': 0.36; "he's": 0.36; 'received:com.au': 0.36; 'subject:?': 0.36; 'unit': 0.37; 'ben': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'catch': 0.60; 'problems.': 0.60; 'subject:Can': 0.60; 'up,': 0.60; 'simply': 0.61; 'refer': 0.63; 'great': 0.65; 'within': 0.65; 'hour': 0.70; '40,000': 0.84; 'received:125': 0.84; 'write:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Can global variable be passed into Python function? Date: Sun, 02 Mar 2014 09:30:20 +1100 References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> <87iorx93o0.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: vmx15867.hosting24.com.au X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:/9BZ6mRTvFbicXcbiPVAutQgQvA= 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393713036 news.xs4all.nl 2869 [2001:888:2000:d::a6]:47808 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67383 Marko Rauhamaa writes: > Steven D'Aprano : > > > It seems to me that he's just assuming that symbols ought to be > > singletons, hence his focus on identity rather than equality. > > Yes. Give that up, then. Your assumption is false in Python, and is not needed to get the behaviour you say you need. > A practical angle is this: if I used strings as symbols and compared > them with "==", logically I shouldn't define them as constants but > simply use strings everywhere Yes, that works fine. It's also quite understandable for the reader. > The principal (practical) problem with that is that I might make a > typo and write: > > if self.state == "IDLE ": > > which could result in some hard-to-find problems. That's just one of a huge variety of problems. Write a comprehensive unit test suite to catch this and a great many other errors. > That's why I want get the help of the Python compiler and always refer > to the states through symbolic constants Python doesn't let you compare symbols, only values. Work within its constraints. -- \ “I cannot conceive that anybody will require multiplications at | `\ the rate of 40,000 or even 4,000 per hour …” —F. H. Wales, 1936 | _o__) | Ben Finney