Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90167
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'expressions': 0.07; 'matches': 0.07; 'string': 0.09; 'anymore.': 0.09; 'deprecated': 0.09; 'here?': 0.09; 'implements': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'strings.': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'bytearray': 0.16; 'concatenate': 0.16; 'data)': 0.16; 'instance:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'split': 0.19; '>>>': 0.22; 'header :User-Agent:1': 0.23; 'bytes': 0.24; 'string,': 0.24; 'unicode': 0.24; 'fine': 0.24; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; '"",': 0.31; 'fast.': 0.31; 'file': 0.32; 'this.': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; "can't": 0.35; 'but': 0.35; 'really': 0.36; 'subject:?': 0.36; 'should': 0.36; 'so,': 0.37; 'to:addr:python-list': 0.38; 'anything': 0.39; 'recent': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'middle': 0.60; 'helps': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'more': 0.64; 'characters,': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Why is array.array('u') deprecated? |
| Date | Fri, 08 May 2015 15:11:35 +0200 |
| Organization | None |
| References | <80167ebf-c5ee-4699-89ca-ef544fe3decc@googlegroups.com> <554c8ff2$0$12990$c3e8da3$5496439d@news.astraweb.com> <93aaa9cd-5d30-44db-9324-4fffe292e9e4@googlegroups.com> <mailman.237.1431084939.12865.python-list@python.org> <7c33ef30-5923-49eb-933c-bfb568cb4753@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd82d4.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.249.1431090704.12865.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431090704 news.xs4all.nl 2905 [2001:888:2000:d::a6]:39961 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:90167 |
Show key headers only | View raw
jonathan.slenders@gmail.com wrote:
>> Can you expand a bit on how array("u") helps here? Are the matches in the
>> gigabyte range?
>
> I have a string of unicode characters, e.g.:
>
> data = array.array('u', u'x' * 1000000000)
>
> Then I need to change some data in the middle of this string, for
> instance:
>
> data[500000] = 'y'
>
> Then I want to use re to search in this text:
>
> re.search('y', data)
>
> This has to be fast. I really don't want to split and concatenate strings.
> Re should be able to process it and the expressions can be much more
> complex than this. (I think it should be anything that implements the
> buffer protocol).
>
> 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:
>>> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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