Matthew Barnett <[email protected]> added the comment:
That behaviour has nothing to do with re.
This line:
samples = filter(lambda sample: not pttn.match(sample), data)
creates a generator that, when evaluated, will use the value of 'pttn' _at that
time_.
However, you then bind 'pttn' to something else.
Here's a simple example:
>>> x = 1
>>> func = lambda: print(x)
>>> func()
1
>>> x = 2
>>> func()
2
A workaround is to capture the current value with a default argument:
>>> x = 1
>>> func = lambda x=x: print(x)
>>> func()
1
>>> x = 2
>>> func()
1
----------
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42475>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com