Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90352
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: Why is array.array('u') deprecated? |
| Date | 2015-05-11 08:03 +0100 |
| References | (2 earlier) <93aaa9cd-5d30-44db-9324-4fffe292e9e4@googlegroups.com> <mailman.237.1431084939.12865.python-list@python.org> <7c33ef30-5923-49eb-933c-bfb568cb4753@googlegroups.com> <mailman.249.1431090704.12865.python-list@python.org> <c603bf41-a9e6-4b28-ab71-1d3ac127c3ec@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.344.1431327837.12865.python-list@python.org> (permalink) |
On 08/05/2015 15:40, jonathan.slenders@gmail.com wrote:
> Le vendredi 8 mai 2015 15:11:56 UTC+2, Peter Otten a écrit :
>>> So, this works perfectly fine and fast. But it scares me that it's
>>> deprecated and Python 4 will not support it anymore.
>>
>> Hm, this doesn't even work with Python 3:
>
> My mistake. I should have tested better.
>
>>>>> data = array.array("u", u"x"*1000)
>>>>> data[100] = "y"
>>>>> re.search("y", data)
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> File "/usr/lib/python3.4/re.py", line 166, in search
>> return _compile(pattern, flags).search(string)
>> TypeError: can't use a string pattern on a bytes-like object
>>
>> You can search for bytes
>>
>>>>> re.search(b"y", data)
>> <_sre.SRE_Match object; span=(400, 401), match=b'y'>
>>>>> data[101] = "z"
>>>>> re.search(b"y", data)
>> <_sre.SRE_Match object; span=(400, 401), match=b'y'>
>>>>> re.search(b"yz", data)
>>>>> re.search(b"y\0\0\0z", data)
>> <_sre.SRE_Match object; span=(400, 405), match=b'y\x00\x00\x00z'>
>>
>> but if that is good enough you can use a bytearray in the first place.
>
> Maybe I'll try that. Thanks for the suggestions!
>
> Jonathan
>
http://sourceforge.net/projects/pyropes/ of any use to you?
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Why is array.array('u') deprecated? jonathan.slenders@gmail.com - 2015-05-08 02:14 -0700
Re: Why is array.array('u') deprecated? wxjmfauth@gmail.com - 2015-05-08 02:37 -0700
Re: Why is array.array('u') deprecated? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-08 20:29 +1000
Re: Why is array.array('u') deprecated? jonathan.slenders@gmail.com - 2015-05-08 04:05 -0700
Re: Why is array.array('u') deprecated? Peter Otten <__peter__@web.de> - 2015-05-08 13:35 +0200
Re: Why is array.array('u') deprecated? jonathan.slenders@gmail.com - 2015-05-08 05:12 -0700
Re: Why is array.array('u') deprecated? Peter Otten <__peter__@web.de> - 2015-05-08 15:11 +0200
Re: Why is array.array('u') deprecated? jonathan.slenders@gmail.com - 2015-05-08 07:40 -0700
Re: Why is array.array('u') deprecated? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-11 08:03 +0100
csiph-web