Possible Duplicate:
How can I get around declaring an unused variable in a for loop?
In Python what is the best practice for naming a variable that is not going to be used? This is an odd question sure, but for my specific case I have a tuple of (key, value) where I am only interested in the value. A basic demo of my use case:
some_stuff = [("key", "value"), ("key2", "value")]
for _, value in some_stuff:
pass # TODO: do something really important with value
I’ve noticed in Eclipse that naming a variable _ or with an _ prefix (e.g. _k) will not show an unused variable warning and removing the _ prefix causes the warning to be raised, but this may just be an oddity/”feature” in Eclipse rather than Python best practice..
Not sure if this is a Eclipse thing or not, but I generally use
'_'to denote values I don’t care about (i.e., return values in tuples, or index values infor-loops).Of course you can always resort to old stand-bys like naming variables
dummyorignore.I’m not sure if PEP 8 mentions anything about this, might be worth peeking into.