Skip to content

Instantly share code, notes, and snippets.

@aodag
Created February 14, 2015 04:33
Show Gist options
  • Save aodag/f86fbd645c39e9dfd007 to your computer and use it in GitHub Desktop.
Save aodag/f86fbd645c39e9dfd007 to your computer and use it in GitHub Desktop.
python3.5からbytesでも%演算子が有効になった。( https://www.python.org/dev/peps/pep-0461/ ) ただしbytesに対する%sはstrでなくbytesを使わなければならない
Python 3.5.0a1 (default, Feb 14 2015, 11:41:57) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b"%s"
b'%s'
>>> b"%s" % 'a'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
>>> b"%s" % b'a'
b'a'
>>> b"%b" % b'a'
b'a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment