[Python-ideas] Hexadecimal floating literals

Steven D'Aprano steve at pearwood.info
Wed Sep 20 21:53:45 EDT 2017


On Thu, Sep 21, 2017 at 11:13:44AM +1000, Nick Coghlan wrote:

> I think so, as consider this question: how do you write a script that
> accepts a user-supplied string (e.g. from a CSV file) and treats it as
> hex floating point if it has the 0x prefix, and decimal floating point
> otherwise?

float.fromhex(s) if s.startswith('0x') else float(s)

[...]
> And if the float() builtin were to gain a "base" parameter, then it's
> only a short step from there to allow at least the "0x" prefix on
> literals, and potentially even "0b" and "0o" as well.
>
> So I'm personally +0 on the idea

I agree with your arguments. I just wish I could think of a good reason 
to make it +1 instead of a luke-warm +0.



-- 
Steve


More information about the Python-ideas mailing list