[issue21954] str(b'text') returns "b'text'" in interpreter

2014-07-10 Thread Ned Deily

Ned Deily added the comment:

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')

>>> 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')

>>> str(b'one')
'one'
>>> b'one'.decode('ascii')
u'one'

https://docs.python.org/2/whatsnew/2.6.html#pep-3112-byte-literals

--
nosy: +ned.deily
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21954] str(b'text') returns "b'text'" in interpreter

2014-07-10 Thread Dev Player

New submission from Dev Player:

str(b'text') returns double quoted item with b prefix within the str() object 
as so: "b'text'" in python interpreter. It seems the "b" shouldn't be within 
the outter quotes or apart of the str() instance data.

Is this a bug or new syntax? I personally haven't see any documentation that 
this is the correct behavior. Nor did I find any previously register issue 
tickets.

>>>bchars_list = [b'o', b'n', b'e']
>>>bchars_list
[b'o', b'n', b'e']
>>>[str(x) for x in bchars_list]
["b'o'", "b'n'", "b'e'"]

--
components: Interpreter Core
files: str bug.bmp
messages: 222718
nosy: devplayer
priority: normal
severity: normal
status: open
title: str(b'text') returns "b'text'" in interpreter
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file35923/str bug.bmp

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com