Re: Can global variable be passed into Python function?

2014-02-21 Thread Ned Batchelder
On 2/21/14 9:47 PM, Dennis Lee Bieber wrote: On Fri, 21 Feb 2014 09:59:17 -0800, Travis Griggs travisgri...@gmail.com declaimed the following: On Feb 21, 2014, at 4:13 AM, Ned Batchelder n...@nedbatchelder.com wrote: Man, do I hate this idea that Python has no variables. It has variables

Re: Can global variable be passed into Python function?

2014-02-21 Thread Steven D'Aprano
On Fri, 21 Feb 2014 07:13:25 -0500, Ned Batchelder wrote: On 2/21/14 2:23 AM, dieter wrote: Samlightai...@gmail.com 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

Re: Can global variable be passed into Python function?

2014-02-21 Thread Ned Batchelder
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: Samlightai...@gmail.com writes: I need to pass a global variable into a python function. Python does not really have the concept variable. What appears

Re: Can global variable be passed into Python function?

2014-02-21 Thread Steven D'Aprano
On Fri, 21 Feb 2014 22:45:14 -0500, Ned Batchelder wrote: 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

Re: Can global variable be passed into Python function?

2014-02-21 Thread Chris Angelico
On Sat, Feb 22, 2014 at 6:20 AM, Marko Rauhamaa ma...@pacujo.net wrote: On the question of how variables can be passed to functions, C, of course, has the operator and Pascal has the var keyword. That doesn't pass a variable into a function, though. It passes the address of that variable, and

Re: Can global variable be passed into Python function?

2014-02-21 Thread Steven D'Aprano
On Fri, 21 Feb 2014 21:20:12 +0200, Marko Rauhamaa wrote: On the question of how variables can be passed to functions, C, of course, has the operator and Pascal has the var keyword. An analogous thing can be achieved in Python 3 (but not in Python 2, I'm afraid). The operator corresponds

Re: Can global variable be passed into Python function?

2014-02-21 Thread Steven D'Aprano
On Sat, 22 Feb 2014 17:36:52 +1100, Chris Angelico wrote: On Sat, Feb 22, 2014 at 6:20 AM, Marko Rauhamaa ma...@pacujo.net wrote: On the question of how variables can be passed to functions, C, of course, has the operator and Pascal has the var keyword. That doesn't pass a variable into a

Re: Can global variable be passed into Python function?

2014-02-21 Thread Chris Angelico
On Sat, Feb 22, 2014 at 6:18 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Now I daresay that under the hood, Pascal is passing the address of foo (or bar) to the procedure plus, but inside plus you don't see that address as the value of b. You see the value of foo (or bar).

Re: Can global variable be passed into Python function?

2014-02-21 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: But your code doesn't succeed at doing what it sets out to do. If you try to call it like this: py x = 23 py y = 42 py swap(x, y) Traceback (most recent call last): File stdin, line 1, in module File stdin, line 2, in swap

Can global variable be passed into Python function?

2014-02-20 Thread Sam
I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by reference in Python? --

Re: Can global variable be passed into Python function?

2014-02-20 Thread dieter
Sam lightai...@gmail.com 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

Re: Can global variable be passed into Python function?

2014-02-20 Thread Peter Otten
Sam wrote: I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by reference in Python? If the variable

<    1   2   3