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
Post a Comment