> Python idiom is to not write getter / setters until (if) you need
> them.  Use attributes instead.  Python Descriptors enable this.
> http://docs.python.org/howto/descriptor.html
>
> class Foo():
>    def __init__(self):
>      self.something = None
>
> users of Foo can get / set .something as they wish.  Later on it's
> decided that setting something needs some logic.  Foo is updated
>
>   def __init__(self):
>     self._something = None
>
>     def set_something(self, val):
>        # do stuff
>        self._something = val
>     def get_something(self):
>        return self._something # or calculate it or whatever
>
>     something = property(get_something, set_something)

Thanks.  That's fascinating and somewhat helpful but I'm not sure how
to use it in my case.  My object model is kind of messy.  I have, very
roughly, something like:

    class TracPM:
         def start(self, task):
             ...do something to get start out of task...
         def finish(self, task):
             ...do something to get finish out of task...

which is then called like:

    for t in tasks:
        start = pm.start(t)

If I create TracPM.__get__() that doesn't relate to the start date, it
relates to the TracPM class.  I guess what I need to do is:

 * Create a ScheduleDate (or PMDate or something) class
 * Give it __get__ and __set__ (and __delete__?) methods
 * Make the dates in the task instances of that class
 * Where I currently do "s = pm.start(t)" I'd do "s = t.start" (which
would invoke the getter) and elsewhere I could do "t.start =
<somedate>" to set it.

Does that sound right?


              Chris

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to