"Don't rebind built-in names*" - it confuses readers

Chris Angelico rosuav at gmail.com
Tue Jun 11 03:20:26 EDT 2013


On Tue, Jun 11, 2013 at 1:30 PM, rusi <rustompmody at gmail.com> wrote:
> Or by example:
>
> def foo(x)...
> def bar(x,y)...
> there is no reason to confuse the two xes.
>
> Whereas
>
> x = ...
> def foo(x)...
> Now there is!
>
> The first should be encouraged, the second discouraged.

Again, there can be good reason for it, such as snapshotting globals:

qwer=123
def asdf(qwer=qwer):
	print("qwer",qwer)

asdf()
qwer=234
asdf()

Done for performance (avoiding lookups), could also be done for
stability (as depicted here) though I've never seen it needed for
that.

ChrisA



More information about the Python-list mailing list