Python handles globals badly.
Chris Angelico
rosuav at gmail.com
Tue Sep 15 21:58:36 EDT 2015
On Wed, Sep 16, 2015 at 11:20 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, 16 Sep 2015 11:13 am, Steven D'Aprano wrote:
>
>> Python is a remarkably clean and consistent language. There's only one
>> kind of value (the object -- everything is an object, even classes are
>> objects). The syntax isn't full of special cases. For example, there's
>> nothing like this horror from Ruby:
>>
>> #!/usr/bin/ruby
>> def a(x=4)
>> x+2
>> end
>>
>> b = 1
>> print "a + b => ", (a + b), "\n"
>> print "a+b => ", (a+b), "\n"
>> print "a+ b => ", (a+ b), "\n"
>> print "a +b => ", (a +b), "\n"
>>
>>
>> which prints:
>>
>> 7
>> 7
>> 7
>> 3
>
>
> Of course it doesn't. It prints:
>
> a + b => 7
> a+b => 7
> a+ b => 7
> a +b => 3
>
>
> Sorry about that.
I'm not a Rubyist, but my reading of this is that the last one is
calling a with +b as its argument, where all the others are calling a
with no argument, and then using the result in an expression. ISTM the
problem here is omitting the parentheses on a function call.
ChrisA
More information about the Python-list
mailing list