Hi Alex, Oh wow I didn't know that, interesting question. If CPython is wrong for bytearray, should IronPython follow the same, unless you think CPython will fix it? Thanks. Danny
Date: Sun, 17 Aug 2014 19:13:59 -0700 Subject: Re: [Ironpython-users] bytearray encoding issue From: slide.o....@gmail.com To: fernandez_d...@hotmail.com You are probably running into this http://ironpython.codeplex.com/workitem/21334. As is mentioned in the issue, I believe this shouldn't really work in cpython, but does because str implements the buffer interface. On Aug 17, 2014 5:21 PM, "Daniel Fernandez" <fernandez_d...@hotmail.com> wrote: Hi All, I ran into an issue bytearray with encoding. The scenario I am using it is with read/writing data over the serial com port. I notice in CPython 2.7.8 the following works >>> bytearray('Michael Gilfix was here\n')bytearray(b'Michael Gilfix was >>> here\n') In IronPython 2.7.5 beta I get the following >>> b = bytearray('Michael Gilfix was here\n')Traceback (most recent call >>> last): File "<stdin>", line 1, in <module>TypeError: unicode argument >>> without an encoding I can get it to work if I do the followingb = bytearray(b'Michael Gilfix was here\n') does the bytearray in CPython do an implicit encoding if not specific to binary? I am trying to use hex with bytearray but I see issues with that as well with encoding. Here is an example CPython 2.7.8>>> hex_string = "deadbeef" >>> hex_data = hex_string.decode("hex")>>> hex_data'\xde\xad\xbe\xef'>>> >>> bytearray(hex_data)bytearray(b'\xde\xad\xbe\xef') IronPython 2.7.5 Beta >>> hex_string = "deadbeef">>> hex_data = hex_string.decode("hex")>>> hex_datau'\xde\xad\xbe\xef' >>> bytearray(hex_data)Traceback (most recent call last): File "<stdin>", line >>> 1, in <module>TypeError: unicode argument without an encoding >>> bytearray(hex_data, 'hex')bytearray(b'deadbeef') Thanks Danny _______________________________________________ Ironpython-users mailing list Ironpython-users@python.org https://mail.python.org/mailman/listinfo/ironpython-users
_______________________________________________ Ironpython-users mailing list Ironpython-users@python.org https://mail.python.org/mailman/listinfo/ironpython-users