Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
initializing mutable class attributes
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Dan Perl, post: 1776489"] My mistake. I shouldn't have made that statement. I don't really know which case happens more often. Having said that, that is probably a mistake that many beginners make. Okay, I have no real way of knowing that either, but I think it's a good assumption. I was using the class attribute as a default, "null", value for the instance attributes. That works just fine for immutable attributes and it allows me not to implement an __init__. I'm leaving the rest of your reply out, but thanks for the suggestion of a metaclass, I'll look into it. After seeing a few replies (yours, Benjamin Niemann's and Peter Otten's) to my initial posting, I think I am getting the picture that there is a conscious decision to keep the use of __init__ the way it is and just make people learn it and learn it early enough. That's a valid approach and I'll accept it. I can also understand your frustration with people who are new to Python, like me, coming from a background in other OO languages, who are not yet comfortable with "the Python way" and feel that there is a "better way" and who suggest changing Python. But you also have to be reallistic and accept that there will always be people coming to Python from other languages and that the adjustment is rather difficult in some areas. You may just say 'Tough!', or you may help them to make that adjustment (I think you are doing that), or you may even accommodate them (you should at least consider that). No one, including you, has given me a reason WHY __init__ is implemented this way. I am not bashing you for that, I would just still like to hear that 'WHY'. I'm sure that this implementation has some advantages. But, coming from a C++ and Java background, where parent default constructors are automatically invoked (well, not always, and that is something that users have to learn too), I find that that approach has some clear advantages. Those are my 2 cents. Dan PS: Does my last name attract the wrong kind of attention from people in this newsgroup? It's really my name, it's not fake, BTW. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
initializing mutable class attributes
Top