A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-April/014456.html below:

[ python-Bugs-416670 ] MatchObjects not deepcopy()able

[Python-Dev] Re: [ python-Bugs-416670 ] MatchObjects not deepcopy()able [Python-Dev] Re: [ python-Bugs-416670 ] MatchObjects not deepcopy()ableMartin v. Loewis martin@loewis.home.cs.tu-berlin.de
Thu, 26 Apr 2001 23:12:45 +0200
> what makes you think a match object is immutable?

Because you cannot modify their state.

> import array, sre
> 
> a = array.array("c", "abcde")
> m = sre.search("bcd", a)
> print m.group(0)

a1 = m.group(0)
a1[0]='z'
print m.group(0)

So you'd have to modify a, to modify m.group(0). To catch this case,
you might want to do

def copy_match(m):
  g = m.group(0)
  if copy(g) is not g:
    raise KeyError    # will be re-raised as copy.Error
  return g

That will restore backwards compatibility with pre, which is what the
submitter of the bug requested.

Regards,
Martin



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4