开发者

Best way to override a installed packge method

开发者 https://www.devze.com 2023-03-28 03:50 出处:网络
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.i

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

精彩评论

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