开发者

Best way to override a installed packge method

I am using django-compress for compression. According to need I want to change on of the function开发者_StackOverflow中文版s in ..../dist-packages/compress/utils.py. How can I override this function.


import compress.utils
utils.compress.function_to_override = overriding_function

Monkey patch it. You'll need to do this before utils is imported anywhere else.

Alternatively, you could create a new Python module, like this:

# fakeutils.py
from compress.utils import *

# make the following line match exactly the overridden function
def function_to_override(var1, etc1, etc2):
    # your version of the function

Then import that module instead:

import fakeutils as utils
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜