Message222724
| Author |
ned.deily |
| Recipients |
devplayer, ned.deily |
| Date |
2014年07月11日.05:30:45 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1405056645.7.0.569639744497.issue21954@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
This is as expected. In Python 3, b'text' represents a bytes object. "Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation".
Also, in the case of simple bytes objects, their str() representation is the same as their repr() representation. For many simple types, the repr() representation of an object allows you to recover the object by using eval().
>>> b'one'
b'one'
>>> type(b'one')
<class 'bytes'>
>>> str(b'one')
"b'one'"
>>> repr(b'one')
"b'one'"
>>> eval(repr(b'one'))
b'one'
>>> b'one'.decode('ascii')
'one'
https://docs.python.org/3/library/stdtypes.html#str
https://docs.python.org/3/library/functions.html#repr
Python 2 (as of 2.6) accepts b'text' literals to make writing code compatible with both Py2 and Py3 easier. However, Py2 treats b'text' the same as 'text'.
>>> b'one'
'one'
>>> type(b'one')
<type 'str'>
>>> str(b'one')
'one'
>>> b'one'.decode('ascii')
u'one'
https://docs.python.org/2/whatsnew/2.6.html#pep-3112-byte-literals |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2014年07月11日 05:30:45 | ned.deily | set | recipients:
+ ned.deily, devplayer |
| 2014年07月11日 05:30:45 | ned.deily | set | messageid: <1405056645.7.0.569639744497.issue21954@psf.upfronthosting.co.za> |
| 2014年07月11日 05:30:45 | ned.deily | link | issue21954 messages |
| 2014年07月11日 05:30:45 | ned.deily | create |
|