dummy, underscore and unused local variables

Tim Johnson tim at johnsons-web.com
Mon Jun 13 11:37:02 EDT 2011


Consider the following code:
for i in range(mylimit):
    foo()
running pychecker gives me a 
"""
Local variable (i) not used 
"""
complaint.
If I use 
for dummy in range(mylimit):
    ....
## or
for _ in range(mylimit):
    ....
I get no complaint from pychecker.	
I would welcome comments on best practices for this issue.
NOTE: I see much on google regarding unused local variables, 
however, doing a search for 'python _' hasn't proved fruitful.

I would like to see comments here specifically on the use for `range'

On a related note: from the python interpreter if I do
>>> help(_) 
I get 
Help on bool object:

class bool(int)
 |  bool(x) -> bool
 ......
 I'd welcome comments on this as well.

 :) I expect to be edified is so many ways, some
 of them unexpected.

 thanks
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com



More information about the Python-list mailing list