monkeypatching - Overriding len in __init__.py - python -
i assign function len in __init__.py
file of package following way:
llen = len len = lambda x: llen(x) - 1
it works fine, in __init__.py
file. how can make affect other modules in package?
when try load name not defined module-level global or function local, python looks in __builtin__
(builtins
in python 3) module. in both versions of python, module availabe __builtins__
in global scope. can modify module , this affect not code python code anywhere runs after code runs!!
import __builtin__ builtins # import builtins in python 3 llen = len builtins.len = lambda a:llen(a) - 1
Comments
Post a Comment