Home » Category » Python

Python: Hash value of wx.DateTime

116| Tue, 06 May 2008 21:05:00 GMT| dalton_tom| 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 & Tags: hash, value, wx.datetime, python

URL: http://programming.itags.org/python/32368/
 
«« Prev - Next »» 0 helpful answers below.

Python Hot Answers

Python New questions

Python Related Categories