python - A Module-level variable and a function argument having the same name: bad practice? -



python - A Module-level variable and a function argument having the same name: bad practice? -

is having x both module-level variable name , function argument name bad practice?

x = 2 def f(x): print x f(x)

i asking because pylint complains it:

w: 3, 6: redefining name 'x' outer scope (line 1) (redefined-outer-name)

no, not, , why seeing warning (w) , not error (e).

in general, depends on utilize case. if example, have alternate variable name can convey same meaning current variable name, improve utilize avoid unnecessary confusion. sample in code, can use:

def f(n): print n

the unnecessary confusion indeed wanted utilize global variable x, or might end comparing values of x different scopes , ending debugging why values not same.

but if using defined variable name in scope best way convey info variable supposed convey, go it.

python python-2.7 pylint

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -