Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pythonic way to write a for loop that doesn't use the loop index

This is to do with the following code, which uses a for loop to generate a series of random offsets for use elsewhere in the program.

The index of this for loop is unused, and this is resulting in the 'offending' code being highlighted as a warning by Eclipse / PyDev

def RandomSample(count):    
    pattern = []
    for i in range(count):
        pattern.append( (random() - 0.5, random() - 0.5) )

    return pattern

So I either need a better way to write this loop that doesn't need a loop index, or a way to tell PyDev to ignore this particular instance of an unused variable.

Does anyone have any suggestions?

like image 422
Adam Luchjenbroers Avatar asked Dec 13 '09 05:12

Adam Luchjenbroers


1 Answers

Just for reference for ignoring variables in PyDev

By default pydev will ignore following variables

['_', 'empty', 'unused', 'dummy']

You can add more by passing supression parameters

-E, --unusednames  ignore unused locals/arguments if name is one of these values

Ref: http://eclipse-pydev.sourcearchive.com/documentation/1.0.3/PyCheckerLauncher_8java-source.html

like image 91
YOU Avatar answered Sep 19 '22 13:09

YOU