Why only one warning in a loop?

It is by design. See the docs at http://docs.python.org/2/library/warnings.html:

Repetitions of a particular warning for the same source location are typically suppressed.

You can override this behavior by adding a filter with the keyword always, as in:

import warnings

warnings.simplefilter('always', UserWarning)
for i in range(10):
   print i
   warnings.warn('this is a warning message')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)