no pass-values calling?

Mel mwilson at the-wire.com
Wed Jan 16 10:52:08 EST 2008


J. Peng wrote:

> Sounds strange.
> In perl we can modify the variable's value like this way:
> 
> $ perl -le '
>> $x=123;
>> sub test {
>>     $x=456;
>> }
>> test;
>> print $x '
> 456

Not all that strange.  The Python equivalent is

x=123
sub test()
     global x
     x=456
test()
print x

Python assignment works by binding an object with a name in a 
namespace.  I suspect that perl does something similar, and the 
differences are in the rules about which namespace to use.

	Mel.



More information about the Python-list mailing list