title: Python - Set class property to depend on values of other properties in the same class
body: <p>Sorry if this already exists somewhere in the question archives, but I'm not sure how to ask it and searching didn't lead to any great revelations.</p>
  
  <p>In Python (2.6.x) I have created a class</p>
  
  <pre><code>class timetuple(object):
      def __init__(self):
          self.weekday = 6
          self.month   = 1
          self.day     = 1
          self.year    = 2011
          self.hour    = 0
          self.min     = 0
          self.sec     = 0
      def jd(self):
          self.jd = julian_date(self)
  
  def julian_date(obj):
      (Code to calculate a Julian Date snipped)
  
  start = timetuple()
  start.day   = 23
  start.month = 2
  start.year  = 2011
  start.hour  = 13
  start.min   = 30
  start.sec   = 0
  
  print start.__dict__
  start.jd()
  print start.__dict__
  print start.jd
  </code></pre>
  
  <p>Which returns</p>
  
  <pre><code>{'hour': 13, 'min': 30, 'month': 2, 'sec': 0, 'weekday': 6, 'year': 2011, 'date': 23, 'day': 1}
  {'hour': 13, 'min': 30, 'month': 14, 'jd': 2455594.0625, 'sec': 0, 'weekday': 6, 'year': 2010, 'date': 23, 'day': 1}
  2455594.0625
  </code></pre>
  
  <p>So the .jd property (or do I call this a function or a method? I'm unsure of the lingo here honestly) doesn't exist before the start.jd() call.  Is there a way I can somehow rewrite this to make it always exist based on the current values in the timetuple class, or have it update itself when the .jd property is called?</p>
  
  <p>I know I can do it the long way by just making a .jd property in the <strong>init</strong>(self) section and then do something like</p>
  
  <pre><code>start = timetuple()
  start.jd = julian_date(start)
  </code></pre>
  
  <p>but I'd like to know how to set up my classes better honestly :)</p>