On 1/17/2014 8:49 AM, Ethan Furman wrote:
%s is restricted in what it will accept::

  - input type supports Py_buffer?
    use it to collect the necessary bytes

  - input type is something else?
    use its __bytes__ method; if there isn't one, raise a TypeError

Examples:

    >>> b'%s' % b'abc'
    b'abc'

    >>> b'%s' % 3.14
    Traceback (most recent call last):
    ...
    TypeError: 3.14 has no __bytes__ method

    >>> b'%s' % 'hello world!'
    Traceback (most recent call last):
    ...
TypeError: 'hello world' has no __bytes__ method, perhaps you need to encode it?

If you produce a helpful error message for str (re: encoding), might it not be appropriate to produce a helpful error message for builtin number types (, perhaps you need a numeric format code?)?
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to