.. _cell-var-from-loop: cell-var-from-loop / W0640 ========================== **Message emitted:** ``Cell variable %s defined in loop`` **Description:** *A variable used in a closure is defined in a loop. This will result in all closures using the same value for the closed-over variable.* **Problematic code:** .. literalinclude:: /data/messages/c/cell-var-from-loop/bad.py :language: python **Correct code:** ``functools.partial.py``: .. literalinclude:: /data/messages/c/cell-var-from-loop/good/functools.partial.py :language: python ``new_function.py``: .. literalinclude:: /data/messages/c/cell-var-from-loop/good/new_function.py :language: python **Related links:** - `Stackoverflow discussion `_ Created by the `variables `__ checker.