On Tue, Apr 17, 2018 at 6:20 PM, Steven D'Aprano <steve at pearwood.info> wrote: > If there are tests which intentionally verify this behaviour, that > really hurts your position that the behaviour is an accident of > implementation. It sounds like the behaviour is intended and required. > It is nonetheless bizarre and unexpected behavior. >>> prefix = 'global' >>> [prefix+c for c in 'abc'] ['globala', 'globalb', 'globalc'] >>> def func(): ... prefix = 'local' ... print([prefix+c for c in 'abc']) >>> func() ['locala', 'localb', 'localc'] >>> class klass: ... prefix = 'classy' ... items = [prefix+c for c in 'abc'] >>> print(klass.items) ['globala', 'globalb', 'globalc'] In Python 2, that last one would produce 'classya' and friends, due to the "broken" comprehension scope. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180417/f510d192/attachment.html>
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