Python: Hash value of wx.DateTime

  • dalton_tom / 116 / Fri, 27 Mar 2009 04:58:00 GMT / Comments (0)
  • Hi,

    I've been using wxPython at work as part of rewriting a lot of our user interface and just wanted to say firstly; thanks to all the developers! It's a really nice package, especially since a lot of our legacy code uses wxWidgets.

    However, I recently ran into what I think might be a problem. While doing some work with DateTimes, I found that wx.DateTime objects representing the same date and time hash to different values. Specifically, they hash to their id. So if you have:

    date1 = wx.DateTime().Set(01,01,2007,12,00,00,00)
    date2 = wx.DateTime().Set(01,01,2007,12,00,00,00)

    then;

    date1 == date2
    True

    but

    date_set = set(date1)
    date2 in date_set
    False

    This is not what I'd expect, as the Python documentation (v2.4.3) says that if you're making your own objects, then the __hash__() method of two equal objects should return the same value for both. Since date1 is equal (as far as I can tell) to date2, I expected it to hash to the same value and thus work as expected in set membership. Is this a bug, or is this intended behaviour? If it's intended behaviour, then can you explain to me why it's this way? If it is intended, then it's no problem as I can always make my own DateTime subclass that just overrides the __hash__() function, but my main concern was that I may have found a bug.

    Thanks for your time :-)

    Tom Dalton
  • Keywords:

    hash, value, wx.datetime, python

  • http://programming.itags.org/python/32368/«« Last Thread - Next Thread »»
  • Python Questions

    • exec'ing functions

      In article <5SPtd.210910$HA.146444@attbi_s01>,Steven Bethard <steven.bethard@gmail.com> ...

      By mel_wilson

    • exec'ing functions

      Mel Wilson wrote:> The_thing_is,_that_once_you_drop_local-namespace> optimization, the entire ...

      By peter_otten

    • why brackets & commas in func calls can't be ommit...

      I have nothing against brackets, and I think Python has used them fortoo much time to allow a so big...

      By bearophilehugs_lycos

    • execfile time out?

      Hello,I'd like to do something like:try:execfile_timeout("somefile.py",5) # time out after 5 seconds...

      By brianblais

    • execl difficulty

      Can anyone tell me why this would cause "Invalid Number of Parameters" whiletrying to compile (or in...

      By pythonnewbie, 9 Comments

    • Speaking of rounding errors...

      Speakign of rounding errors, why is round() defined to round away fromzero? I've always been qu...

      By christopher_t_king, 2 Comments

    • Speaking of rounding errors...

      Speakign of rounding errors, why is round() defined to round away fromzero? I've always been qu...

      By christophertking, 2 Comments

    • exec'ing functions (WAS: updating locals() and glo...

      Jeff Shannon wrote:> Note also that functions which use exec cannot use the static namespace> ...

      By steven_bethard, 2 Comments

    • Another parsing question

      I have the following that I am using to extract "numbers' from a fileprompt1 = raw_input('...

      By jaymutteriii, 5 Comments