.. _redefined-loop-name:

redefined-loop-name / W2901
===========================

**Message emitted:**

Redefining %r from loop (line %s)

**Description:**

*Used when a loop variable is overwritten in the loop body.*

**Problematic code:**

.. literalinclude:: /data/messages/r/redefined-loop-name/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/r/redefined-loop-name/good.py
   :language: python




.. note::
  This message is emitted by the optional :ref:`'redefined-loop-name'<pylint.extensions.redefined_loop_name>`
   checker which requires the ``pylint.extensions.redefined_loop_name`` plugin to be loaded.

Created by the `redefined-loop-name <https://github.com/PyCQA/pylint/blob/main/pylint/extensions/redefined_loop_name.py>`__ checker.