python - How to restore a builtin when parameter has same name? -
i know you're "not supposed to" use builtin names parameters functions, make sense:
def foo(range=(4,5), type="round", len=2):
but if has been done, , range
variable has been processed , no longer needed, how builtin range
, use inside foo()
?
del range
doesn't restore builtin:
unboundlocalerror: local variable 'range' referenced before assignment
for python 2.x
import __builtin__ range = __builtin__.range
for python 3.x
import builtins range = builtins.range
Comments
Post a Comment