是否有可能在Python中使用猴子补丁列表文字?

时间:2019-11-25 19:03:08

标签: python

我想做这样的事情

import builtins


class HackedList(list):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def __getitem__(self, item):
        pass # my code here

builtins.list_literal = HackedList # there is no such thing as list_literal, only list which seems to have no effect on literal itself

我需要重写内置函数,而不是子类。

0 个答案:

没有答案