Anthony Kuhlman <[EMAIL PROTECTED]> wrote:
> Pythoners,
> I'm having trouble understanding the behavior of global variables in a
> code I'm writing. I have a file, test.py, with the following contents
>
> foo = []
>
> def goo():
> global foo
> foo = []
> foo.append(2)
>
> d
On Fri, 08 Aug 2008 13:10:48 -0400, Anthony Kuhlman wrote:
> I'm having trouble understanding the behavior of global variables in a
> code I'm writing. I have a file, test.py, with the following contents
>
> foo = []
>
> def goo():
> global foo
> foo = []
> foo.append(2)
>
> def mo
Pythoners,
I'm having trouble understanding the behavior of global variables in a
code I'm writing. I have a file, test.py, with the following contents
foo = []
def goo():
global foo
foo = []
foo.append(2)
def moo():
print foo
In an ipython session, I see the following:
In [1]
Laurent Pointal wrote:
> Yes, and i replies: "which contains a foo assignment. As foo is
> not defined "global", it is considered to be local. "
>
> Maybe my explanation was not clear enough with variable foo to be
> considered local because there is an *assignment* to foo.
Yep, thanks for the
Bjoern Schliessmann wrote:
> Laurent Pointal wrote:
>
>> And so the solution to add "global foo" before using it.
>
> Didn't you read his final question?
Yes, and i replies: "which contains a foo assignment. As foo is not
defined "global", it is considered to be local. "
Maybe my explanation w
Ed Jensen <[EMAIL PROTECTED]> wrote:
> I'm having a vexing problem with global variables in Python.
Thanks to everyone who replied. The peculiar way Python handles
global variables in functions now makes sense to me.
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 2, 5:29 pm, Bjoern Schliessmann wrote:
> Laurent Pointal wrote:
> > And so the solution to add "global foo" before using it.
>
> Didn't you read his final question?
>
> | All of a sudden, tiny() can see the global variable "foo". Very
> | confusing! Why is it that tiny() sometimes can, an
Bjoern Schliessmann schreef:
> Laurent Pointal wrote:
>
>> And so the solution to add "global foo" before using it.
>
> Didn't you read his final question?
>
> | All of a sudden, tiny() can see the global variable "foo". Very
> | confusing! Why is it that tiny() sometimes can, and sometimes
>
Bjoern Schliessmann wrote:
> Laurent Pointal wrote:
>
>> And so the solution to add "global foo" before using it.
>
> Didn't you read his final question?
>
> | All of a sudden, tiny() can see the global variable "foo". Very
> | confusing! Why is it that tiny() sometimes can, and sometimes
> |
Laurent Pointal wrote:
> And so the solution to add "global foo" before using it.
Didn't you read his final question?
| All of a sudden, tiny() can see the global variable "foo". Very
| confusing! Why is it that tiny() sometimes can, and sometimes
| can't, see the global variable "foo"?
I hav
Ed Jensen a écrit :
> I'm having a vexing problem with global variables in Python. Please
> consider the following Python code:
>
> #! /usr/bin/env python
>
> def tiny():
> bar = []
> for tmp in foo:
> bar.append(tmp)
> foo = bar
>
Ed Jensen wrote:
> #! /usr/bin/env python
>
> def tiny():
> bar = []
> for tmp in foo:
> bar.append(tmp)
> foo = bar
>
> if __name__ == "__main__":
> foo = ['hello', 'world']
> tiny()
Like this ?
#! /usr/bin/env python
def tiny():
bar = []
gobal foo
for tmp in foo:
bar.ap
I'm having a vexing problem with global variables in Python. Please
consider the following Python code:
#! /usr/bin/env python
def tiny():
bar = []
for tmp in foo:
bar.append(tmp)
foo = bar
if __name__ == "__main__":
foo = ['hello', 'wor
13 matches
Mail list logo