[ase-users] ase-db question on booleans
Ask Hjorth Larsen
asklarsen at gmail.com
Fri Mar 3 14:09:45 CET 2017
Hi
2017-03-03 2:39 GMT+01:00 John Kitchin via ase-users
<ase-users at listserv.fysik.dtu.dk>:
> Hi all,
>
> In ase.db.core there is this function:
>
> def convert_str_to_int_float_or_str(value):
> """Safe eval()"""
> try:
> return int(value)
> except ValueError:
> try:
> value = float(value)
> except ValueError:
> value = {'True': 1.0, 'False': 0.0}.get(value, value)
> return value
>
> I wondered why True and False are converted to floats? It seems strings
> like True and False would be better, or integers. Is there some database
> that can not store booleans where this is useful?
Right. If anything relies on that behaviour, it should probably be
changed anyway.
I think the strings 'True' and 'False' could be ignored, but we could
also convert them to proper booleans if we want it to be more like an
actual eval(). Converting True and False to something that is not a
boolean seems too illogical.
(Since True and False are actually ints, we don't need to rename the
function :))
Best regards
Ask
More information about the ase-users
mailing list