Storing instances using jsonpickle
dan at tombstonezero.net
Fri Sep 5 06:38:17 CEST 2014
On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote:
> On Thu, Sep 4, 2014 at 9:39 AM, MRAB <python at mrabarnett.plus.com> wrote:
>> The key of a dict could also be int, float, or tuple.
> Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that
> outlandish an idea...
Using floats is a bad idea. Consider this python code:
dictionary = dict()
original = get_some_floating_point_value()
dictionary[original] = 'foo'
string_version = str(original) # this is where things head south
duplicate = float(string_version)
value = dictionary.get(duplicate)
Okay, so what is value? Is it 'foo'? Is it None?
(Yes, I can fix this. If I *know* that original is a float, then I
could use original.hex() instead of str(original).)
More information about the Python-list