Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'operator': 0.03; 'languages,': 0.04; 'subject:Python': 0.06; 'assignment': 0.07; 'compiler': 0.07; 'level,': 0.07; 'pypy': 0.07; 'optimizing': 0.09; 'subject:into': 0.09; 'things,': 0.09; 'cc:addr:python-list': 0.11; 'thread': 0.14; '"int': 0.16; '23,': 0.16; 'allocates': 0.16; 'declared': 0.16; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'latter,': 0.16; 'recorded': 0.16; 'segment': 0.16; 'sense,': 0.16; 'subject:variable': 0.16; 'valid.': 0.16; 'variables,': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'stack': 0.19; 'feb': 0.22; 'machine': 0.22; 'cc:addr:python.org': 0.22; 'days,': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'points': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'becoming': 0.31; "d'aprano": 0.31; 'maintains': 0.31; 'steven': 0.31; 'there.': 0.32; 'stuff': 0.32; 'another': 0.32; 'style': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'similar': 0.36; 'so,': 0.37; 'pm,': 0.38; 'does': 0.39; 'either': 0.39; 'space': 0.40; 'even': 0.60; 'subject:Can': 0.60; 'tell': 0.60; 'free': 0.61; 'address': 0.63; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'records': 0.73; 'address,': 0.75; 'difference.': 0.84; 'kinda.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=KzB+7uUGmboqPHrjefdg//oYs6F1HPMhac/fdfGm5OQ=; b=KtexD2uVCRqkVUCAAJPZoI0sLJwNPVNNfYNlna3JyI6phcz/gQU4/HbFt0m6HMtCJF Ibmsdxz6ubD7DfnAlUj8Tkly0TWPczpRXvZWHCbBtNeXiGYqO+RUR+60SS5WKjZF4/pJ +mC2q9XMib+vVlkzZoNV4zT9B3NxTl2TwCaKmx1rbaHZCW2EZ5YMQR7lLXJn+D8x+1jM hAoQvHyM6MlSykjWgtWalQ2PfkzveaKiWnL6MCNOufz4OVL6fyxiUCGucFZs6TwgObx+ kSrrgjGJ/jrsp8KB8c8N0dSSui3q9bQU0053AxuTBf9ISMFfOR4Iz4rlcVo3Q8Lpi4Nl ejww== MIME-Version: 1.0 X-Received: by 10.68.162.66 with SMTP id xy2mr17377582pbb.46.1393120227063; Sat, 22 Feb 2014 17:50:27 -0800 (PST) In-Reply-To: <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 23 Feb 2014 12:50:26 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393120230 news.xs4all.nl 2846 [2001:888:2000:d::a6]:36476 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66912 On Sun, Feb 23, 2014 at 12:39 PM, Steven D'Aprano wrote: > In C or Pascal-style languages, what we might call the "fixed address" > style of variables, a variable assignment like xyz = 1 does something > like this: > > - associate the name 'xyz' with some fixed location > - stuff the value 1 into that location Kinda. In its purest sense, C is like that. When you declare "int xyz;", the compiler allocates one machine word of space either in the data segment (if that's at top level, or is declared static) or on the stack (if it's local), and records that the name xyz points there. But an optimizing C compiler is allowed to do what it likes, as long as it maintains that name binding... and as long as any recorded address of it remains valid. It's actually very similar to what was discussed in another thread recently about PyPy and the id() function - the compiler's free to have xyz exist in different places, or not exist at all, as long as the program can't tell the difference. I don't know whether PyPy allocates an id for everything or only when you call id(), but if the latter, then it's exactly the same as a C compiler with the address-of operator - if you never take the address, it doesn't have to have one (and even if you do, it's free to fiddle with things, unless you declare the variable volatile). So, these days, C is becoming more like Python. ChrisA