Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'true,': 0.04; 'false.': 0.07; 'subject:skip:c 10': 0.07; 'python': 0.09; '%r"': 0.09; 'arg': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sees': 0.16; 'verbose': 0.16; 'module': 0.19; 'appropriate': 0.20; 'skip:- 40': 0.21; 'header:X-Complaints-To:1': 0.28; 'subject:list': 0.28; 'fri,': 0.30; 'function': 0.30; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'false': 0.35; 'received:org': 0.36; 'created': 0.36; 'charset:us-ascii': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'more': 0.63; 'behavior': 0.64; 'jul': 0.65; 'analog': 0.84; 'wrong...': 0.84; 'dennis': 0.91; 'rusi': 0.91; 'subject:funny': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: lambda in list comprehension acting funny Date: Fri, 13 Jul 2012 13:47:02 -0400 Organization: > Bestiaria Support Staff < References: <03943ea6-5914-4de4-821c-055bed1d5804@f9g2000pbd.googlegroups.com> <4fffc1fd$0$29965$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-253-106-193.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342201638 news.xs4all.nl 6911 [2001:888:2000:d::a6]:34779 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25277 On Fri, 13 Jul 2012 06:44:59 -0700 (PDT), rusi declaimed the following in gmane.comp.python.general: > Heres a more appropriate analog > > ------------------------------------------ > VERBOSE = True > > def function(arg): > if VERBOSE: > print("calling function with arg %r" % arg) > process(arg) > > def caller(): > VERBOSE = False > function(1) > > --------------------------------------------- > Python semantics: function sees VERBOSE False Wrong... "function" still sees the module level VERBOSE with a value of True, whereas "caller" created a local VERBOSE set to False. To get your behavior needs: def caller(): global VERBOSE VERBOSE = False function(1) > Haskell semantics: function sees VERBOSE True -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/