Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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; 'modified': 0.05; 'refers': 0.07; 'python': 0.08; 'mutable': 0.09; 'pm,': 0.10; 'wrote:': 0.14; '(lambda': 0.16; '2:18': 0.16; 'closure.': 0.16; 'lambda': 0.16; 'scope,': 0.16; 'anonymous': 0.16; 'tue,': 0.17; 'of.': 0.19; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'problem?': 0.23; 'received:209.85.161.46': 0.23; 'received :mail-fx0-f46.google.com': 0.23; 'function': 0.25; 'received:209.85.161': 0.26; 'object': 0.26; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; 'functions.': 0.29; 'calling': 0.31; 'to:addr:python-list': 0.33; 'post': 0.33; 'list': 0.33; '...': 0.34; 'there': 0.35; 'itself,': 0.35; 'reference': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'case': 0.37; 'problem.': 0.38; 'run': 0.38; 'creates': 0.38; 'subject:: ': 0.38; 'called': 0.39; 'received:209': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.39; 'within': 0.60; 'your': 0.60; '31,': 0.65; 'designed,': 0.84; 'problem...': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=g0c1YsZ72feIwsZiextaLLEWbuWCtPHR2n4mWM3qvU4=; b=oEXtVpp2u7s7Ij+gCSFvM1N2Ok3GHG4JJ8i4GBdGHmntOj96Ms3s8NQCp2ZrLOMdGg 56yHTGg2RT6LQKNmspJaMG1aWcfCI4mDLquJD0UYoOWeQ8BwCqSF2qGAr8l2LRlQDFqH 9YVlGBsX/66dh6dfgD3isXM5B7pa3p1Qw1jek= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=vy88WtQyGSCO+p3+kfXUOiXDkOchmdQHwmOMFU4RzbHOkDX4yS9ziGn0C0iEGTUd1C thF6Y9PUhI8oOkyHF1R85a58dI6KPVuuwCanKL9sTzH1yJvGe8BX+aPCXtqJooxfGeqm 3DlqizhwGIMpMX98LmcuNoQ4B+ZpZT4Sozna0= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Tue, 31 May 2011 16:24:27 -0600 Subject: Re: Something is rotten in Denmark... To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 25 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306880699 news.xs4all.nl 49046 [::ffff:82.94.164.166]:59510 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6762 On Tue, May 31, 2011 at 2:18 PM, harrismh777 wrot= e: > If I'm understanding that correctly, then that means lambda is working as > designed, and that there are very subtle nuances to be aware of. In my > little case > > =A0 (lambda n: i + n) > > =A0 ... if the =A0i =A0goes out of scope before the anonymous function ge= ts called > then we have a problem... or if =A0i =A0 as a reference is mutable or ref= ers to > a different object before the anonymous function is called then we have a > problem? Actually, if i merely goes out of scope, there is no problem. It just creates a closure. It's only when the i within that scope is modified that we run into problems. In fact, in Python 3 the scope of a list comprehension variable is the list comprehension itself, so in your original post i was already out of scope by the time you started calling the lambda functions. Cheers, Ian