[issue22549] bug in accessing bytes, inconsistent with normal strings and python 2.7

2017-02-22 Thread Marco Buttu

Changes by Marco Buttu :


--
pull_requests: +203

___
Python tracker 

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



[issue22549] bug in accessing bytes, inconsistent with normal strings and python 2.7

2014-10-03 Thread Kevin Hendricks

Kevin Hendricks added the comment:

Thanks for letting me know this was expected behaviour.  I see the same "issue" 
holds true while using:

for c in b'0123456789':
   print(ord(c))
 
I ended up using slices nearly everyplace.  Still ran into iterator issues.  
Horrible hack really.  

I think I will spend some time reading the python dev archives to figure out 
how anyone could defend this approach.

FWIW, introducing a bytes class that works exactly like byte (non-unicode 
strings) in python 2.X but disallowing any automatic up-conversion to full 
unicode (like during concatenation), would have been a useful step.  

I work on decoding binary formatted ebook files all of the time, and python 3's 
second class treatment of bytes makes no sense to me.  Perfectly valid code can 
be written using only utf-8 and latin-1 encoded bytestrings with no need to 
upconvert to anything.  It is practically impossible to support code like that 
in Python 3.

Boggles the mind.

Thanks again for the fast response.

Kevin

--

___
Python tracker 

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



[issue22549] bug in accessing bytes, inconsistent with normal strings and python 2.7

2014-10-03 Thread R. David Murray

R. David Murray added the comment:

Agreed, but that is a design decision that was taken long ago (regretted by 
more than a few but defended by others).  You can find a number of discussions 
of this by searching the python-dev archives, including some more recent 
discussions on possibilities for lessening the pain, but I don't remember if 
any of those turned into real proposals.

For now, you can find some helpers in six, or you can write your code using 
slice notation (b'abc'[1:2] == b'b').

--
nosy: +r.david.murray
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



[issue22549] bug in accessing bytes, inconsistent with normal strings and python 2.7

2014-10-03 Thread Kevin Hendricks

New submission from Kevin Hendricks:

Hi,

I am working on porting my ebook code from Python 2.7 to work with both Python 
2.7 and Python 3.4 and have found the following inconsistency I think is a bug 
...

KevinsiMac:~ kbhend$ python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> o = '123456789'

>>> o[-3]
'7'

>>> type(o[-3])


>>> type(o)


the above is what I expected but under python 3 for bytes you get the following 
instead:

>>> o = b'123456789'

>>> o[-3]
55

>>> type(o[-3])


>>> type(o)

 


When I compare this to Python 2.7 for both bytestrings and unicode I see the 
expected behaviour. 

Python 2.7.7 (v2.7.7:f89216059edf, May 31 2014, 12:53:48) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.


>>> o = '123456789'

>>> o[-3]
'7'

>>> type(o[-3])


>>> type(o)



>>> o = u'123456789'

>>> o[-3]
u'7'

>>> type(o[-3])


>>> type(o)



I would consider this a bug as it makes it much harder to write python code 
that works on both python 2.7 and python 3.4

--
components: Interpreter Core
messages: 228348
nosy: kevinbhendricks
priority: normal
severity: normal
status: open
title: bug in accessing bytes, inconsistent with normal strings and python 2.7
type: behavior
versions: Python 2.7, Python 3.4

___
Python tracker 

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