[Python-Dev] PEP 460: allowing %d and %f and mojibake (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Jan 14 22:59:15 CET 2014


Guido van Rossum wrote:

def spam(a): r = asciistr('(') if a: r += a.strip() r += asciistr(')') return r

The general fix would be to add else: r += a[:0]

The awkwardness might be reducable if asciistr let you write something like

r = asciistr('(', a)

meaning "give me either a string or bytes containing the value '(', depending on the type of a".

But taking a step back, how bad would it really be if an asciistr were returned in this case? Is it just that asciistr doesn't behave exactly like a str in all situations, so it might break something?

If so, would it help if asciistr were a built-in type, so that other things could be made aware of it?

-- Greg



More information about the Python-Dev mailing list