[Python-ideas] More alternate constructors for builtin type

Greg Ewing greg.ewing at canterbury.ac.nz
Tue May 7 08:18:34 EDT 2019


Steven D'Aprano wrote:

> That suggests a possible pair of constructors:
> 
>     bytes.from_int(n)  -> equivalent to b'%d' % n
>     bytes.ord(n)       -> equivalent to bytes((n,))

I don't see how bytes.from_int(n) is any clearer about what it
does than just bytes(n). If we're going to have named constructors,
the names should indicate *how* the construction is being done,
not just repeat the type of the argument.

-- 
Greg


More information about the Python-ideas mailing list