title: How to check if a datetime object is localized with pytz?
body: <p>I want to store a datetime object with a localized UTC timezone. The method that stores the datetime object can be given a non-localized datetime (naive) object or an object that already has been localized. How do I determine if localization is needed?</p>
  
  <p>Code with missing if condition:</p>
  
  <pre><code>class MyClass:
    def set_date(self, d):
      # what do i check here?
      # if(d.tzinfo):
        self.date = d.astimezone(pytz.utc)
      # else:
        self.date = pytz.utc.localize(d)
  </code></pre>