Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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; 'true,': 0.05; 'subject:Python': 0.06; 'assign': 0.07; 'reject': 0.07; 'variables': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'variable,': 0.09; 'variables.': 0.09; 'python': 0.11; '"python': 0.16; 'assumptions': 0.16; 'behave': 0.16; 'insisted': 0.16; 'itself,': 0.16; 'program),': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rules.': 0.16; 'semantics': 0.16; 'subject:variable': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; 'thanks.': 0.20; 'seems': 0.21; 'feb': 0.22; '>>>': 0.22; 'appears': 0.22; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'question': 0.24; 'define': 0.26; 'pass': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; "doesn't": 0.30; 'gives': 0.31; 'went': 0.31; 'context,': 0.31; "d'aprano": 0.31; 'pascal': 0.31; 'steven': 0.31; 'view.': 0.31; 'writes:': 0.31; 'languages': 0.32; 'quite': 0.32; 'fri,': 0.33; 'guess': 0.33; 'actual': 0.34; 'sense': 0.34; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'really': 0.36; 'earth': 0.36; 'done': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'too': 0.37; 'question,': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'subject:Can': 0.60; 'most': 0.60; 'introduced': 0.61; 'course': 0.61; 'simple': 0.61; 'name': 0.63; 'skip:n 10': 0.64; 'decided': 0.64; 'different': 0.65; 'natural': 0.68; 'sam': 0.68; 'fact,': 0.69; 'risk': 0.72; 'attention': 0.75; 'power': 0.76; '"can': 0.84; 'batchelder': 0.84; 'confusion.': 0.84; 'perspective,': 0.84; 'hate': 0.91; 'besides,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: Can global variable be passed into Python function? Date: Fri, 21 Feb 2014 22:45:14 -0500 References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <5308194f$0$29985$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <5308194f$0$29985$c3e8da3$5496439d@news.astraweb.com> 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393040726 news.xs4all.nl 2897 [2001:888:2000:d::a6]:34797 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66871 On 2/21/14 10:28 PM, Steven D'Aprano wrote: > On Fri, 21 Feb 2014 07:13:25 -0500, Ned Batchelder wrote: > >> On 2/21/14 2:23 AM, dieter wrote: >>> Sam writes: >>> >>>>> I need to pass a global variable into a python function. >>> Python does not really have the concept "variable". >>> >>> What appears to be a variable is in fact only the binding of an object >>> to a name. If you assign something to a variable, all you do is binding >>> a different object to the name. >>> >>> >> Man, do I hate this idea that Python has no variables. It has variables >> (names associated with values, and the values can change over the course >> of the program), they just don't work the same as C or Fortran >> variables. In fact, they work exactly the same as Javascript or Ruby >> variables. > > I sympathise with your view. It seems quite ridiculous to claim that > Python has no variables. If it has no variables, what on earth does it > mean when we say "x = 42"? > > But the very ridiculousness is what gives it the attention-grabbing power > that makes it a useful meme. "Python variables don't behave like C > variables" might be true, but it's also wish-washy and forgettable. > > In my own case, I never quite got Python's name binding semantics until I > was introduced to the "Python has no variables" meme. That got my > attention long enough to listen to the actual message: my assumptions > about how variables behave was based on Pascal semantics, and Python > doesn't quite follow the same rules. Consequently, if I implicitly define > "variable" to mean "Pascal variables", as I had been, then Python has no > variables, it has these things called "name bindings". > > That's when I got it. > > I went through a phase where I too insisted that Python had no variables. > But then my natural laziness asserted itself, and I decided that the word > "variable" is too useful to always reject it (and besides, C- and Pascal- > like languages don't have a monopoly on the word "variable"). Now, I use > the terms "variable" or "reference" or "name binding" as I feel makes the > most sense in context, depending on my best guess of the risk of > misunderstanding or confusion. > > This is an interesting perspective, thanks. I think it might be that the OP's question, "Can a global variable be passed into a function", really had nothing to do with the name/value/variable distinction, and we've done it again: taken a simple question and spun off into pedantry and trivia. -- Ned Batchelder, http://nedbatchelder.com