Python handles globals badly.
rosuav at gmail.com
Wed Sep 16 03:58:36 CEST 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:
>> def a(x=4)
>> 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:
> 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.
More information about the Python-list