Home > OS >  Preferable way to get rid of 'redefined-outer-name' from pylint
Preferable way to get rid of 'redefined-outer-name' from pylint

Time:12-06

For the following Python code

def add_func(a,b):
    print(a b)

a = 2
b = 3
add_func(a,b)

pylint will state

 W0621: Redefining name 'a' from outer scope (line 4) (redefined-outer-name)
...

I can rename it as (perhaps due to a and b outside function will interfere add_func)

a_input = 2
b_input = 3
add_func(a_input,b_input)

to get rid of the message from pylint. But, _input looks somehow lengthy. Is there any recommended coding practice to get rid of the outer scope message from pylint?

CodePudding user response:

the main usecase of a function is to pass arguments directly into it, so in this case the simplest way to input those would be:

add_func(2,3)

If you want to pass in varibales, name them after their usecase for readability purposes (It is generally not recommended to have a single char as variable name, with a few exceptions like i for loops)

  • Related