stchris / untangle

Converts XML to Python objects
MIT License
612 stars 83 forks source link

Consider "getter" for attributes? #74

Closed ventz closed 4 years ago

ventz commented 4 years ago

Would you consider providing a "get" method for the attributes?

https://github.com/stchris/untangle/blob/072e9f88773d61d312bd956e07ac39145d9edd5b/untangle.py#L47

While it can be accessed with ojb._attributes, it would be helpful to have an "official" method that won't go away/change potentially. Having access to the attributes is helpful if you are trying to store large amounts of attributes as a direct dictionary into a list. Essentially what you have without the "Element" class.

ventz commented 4 years ago

And I fully understand if reference/your view is: https://dirtsimple.org/2004/12/python-is-not-java.html

Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans. Do not write getters and setters. This is what the ‘property’ built-in is for. And do not take that to mean that you should write getters and setters, and then wrap them in ‘property’. That means that until you prove that you need anything more than a simple attribute access, don’t write getters and setters. They are a waste of CPU time, but more important, they are a waste of programmer time. Not just for the people writing the code and tests, but for the people who have to read and understand them as well.

:)

ventz commented 4 years ago

The more I read about "the python way", the more I am convinced that this is unnecessary. Closing.