On Fri, Jan 14, 2005 at 08:11:32PM -0500, Kent Johnson wrote:- typical Python style is *not* to define setter and getter functions. If you need to mediate attribute access you can do it later using properties.
I treid to figure out how this works with no luck. It seems that when you use property, you don't necessarily update the attribute. It seems I want the setattr() and getattr() functions? I always thought it was bad programming to alter an attribute directly in OO programming, but it seems I am mistaken?
Well, in Java and C++ programming that is what I was taught. Python culture is different and it seems to work OK.
class Backup:
__init__(self): self.some_var = 5
burn_obj = Burn(self)
class Burn:
__init__(self, main): setattr(main, 'some_var', 6)
main.some_var = 6 will work just fine.
The reason that is given for using accessors is that it gives you a layer of flexibility; if you want to change the representation of the data, or make it a computed attribute, you can do that without impacting clients.
Python, instead, lets you change what attribute access means. The way to do this is with 'properties'. This is kind of an advanced topic, here are two references: http://www.python.org/2.2.1/descrintro.html#property
http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html#SECTION000340000000000000000
???
- you might want to consolidate your classes into a small number of modules. This is the style of much of the Python standard library. Look at optparse.py for an example (picked more-or-less at random).
I couldn't find the optparse.py module.
It's in the standard library - /lib/optparse.py
Kent
But looking at other packages
and modules, it seems that the one module shouldn't run more than 500 lines. I * could* consolidate many of my classes in one file, but that would make very long files.
Thanks
Paul
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor