New PEP: Attribute Access Handlers
Paul Prescod
paul at prescod.net
Sat Jul 22 01:09:08 EDT 2000
Bjorn Pettersen wrote:
>
> Justification, Scenario 4:
>
> An existing class has a string attribute, however the most common
> operation on it is appending to the end. Through the profiler you find
> that this operation is taking up 95% of the applications time. You want
> to change the implementation to cStringIO for efficiency (total
> execution time for your application goes from 90 seconds to 3 secs).
Actually, I'm not sure if my proposal would help here. Appending to a
cStringIO is not an assignment operation...
> Perhaps you should add a few words about why you chose __attr_XXX__
> instead of __set/get/del_XXX__?
That was actually the first proposal. But inheritance could get
confusing if you inherited set without get or get without set etc.
> Would both of them work for
> introspection for e.g. a GUI builder? I seem to remember that JavaBeans
> <shudder> looks for the presence of set/get methods to make attributes
> available, I'm not sure if Python could look at an objects __dict__ for
> that information under this proposal?
Interesting question...I think that's not a bad idea, actually. ON the
other hand, Python is so dynamic that there are other (more flexible)
ways that might not work in Java:
class foo:
k=5
j=7
def a(): pass
....
__readonly_properties__=[k,...]
__readwrite_properties__=[j,...]
....
--
Paul Prescod - Not encumbered by corporate consensus
New from Computer Associates: "Software that can 'think', sold by
marketers who choose not to."
More information about the Python-list
mailing list