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/2011-May/111440.html below:

[Python-Dev] Don't set local variable in a list comprehension or generator

[Python-Dev] Don't set local variable in a list comprehension or generator [Python-Dev] Don't set local variable in a list comprehension or generatorBenjamin Peterson benjamin at python.org
Wed May 18 15:41:48 CEST 2011
2011/5/18 Victor Stinner <victor.stinner at haypocalc.com>:
> Hi,
>
> ''.join(c for c in 'abc') and ''.join([c for c in 'abc']) do create a
> temporary c variable. In this case, the variable is useless and requires
> two opcodes: STORE_FAST(c), LOAD_FAST(c). The variable is not available
> outside the list comprehension/generator.
>
> I would like to remove the variable in these cases to speed up
> (micro-optimize!) Python.
>
> Remove the variable breaks code using introspection like:
>
>   list([locals()['x'] for x in range(3)])
>
> We may detect the usage of introspection (I don't know how hard it is),
> only optimize trivial cases (like "x for x in ..."), or only optmize
> with Python is running in optimize mode (python -O or python -OO).
>
> What do you think? Is it useless and/or stupid?

Far more useful would be figuring out how to remove the call.



-- 
Regards,
Benjamin
More information about the Python-Dev mailing list

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