|
|
|
|
|
by DeepDuh
5031 days ago
|
|
Not the one you replied to, but one thing that hits me as awkward is the default static behavior of variables. something like class Foo:
bar = 1
means that bar is now a static class member (static in Java's sense). It needs to be assigned to "1" explicitly in __init__ as far as I understand. That's just unintuitive and leads to lots of boilerplate, just so that you don't need specifiers like 'static'. Sometimes the fear of verbosity gets in the way of intuitiveness. |
|
There's no default anything, what you wrote sets "bar = 1" on the class itself, nothing more an nothing less, just as if you'd written:
(in fact that's pretty much what the class statement is sugar for)If you want to set it on the instance, set it on the instance.
Python's class context is a namespace like every other, you can do any computation you wish in there, and at the end the ``class`` statements collects all bindings of the namespace and sets them on the class.