小编Ale*_*lex的帖子

仅导入类静态方法

我在基类中有以下装饰器:

class BaseTests(TestCase):
    @staticmethod
    def check_time(self, fn):
        @wraps(fn)
        def test_wrapper(*args,**kwargs):
            # do checks ...
        return test_wrapper
Run Code Online (Sandbox Code Playgroud)

以下类继承自BaseTests:

from path.base_posting import BaseTests
from path.base_posting.BaseTests import check_time  # THIS LINE DOES NOT WORK!

class SpecificTest(BaseTests):

    @check_time # use the decorator
    def test_post(self):
        # do testing ...
Run Code Online (Sandbox Code Playgroud)

我想在上面的SpecificTest中使用装饰器,而不必使用BaseTests.check_time,因为在原始代码中他们有很长的名字,我必须在很多地方使用它.有任何想法吗?

编辑:我决定让check_time成为BaseTests文件中的一个独立函数,并简单地导入

from path.base_posting import BaseTests, check_time
Run Code Online (Sandbox Code Playgroud)

python import inheritance

14
推荐指数
1
解决办法
1万
查看次数

删除或编辑使用Python泡菜保存的条目

我基本上会执行转储和加载的序列,但是在某些时候我想删除已加载的条目之一。我怎样才能做到这一点?有没有办法删除或编辑用Python pickle / pickckle保存的条目?

编辑:数据用pickle保存在一个二进制文件中。

python binary pickle

5
推荐指数
1
解决办法
7430
查看次数

标签 统计

python ×2

binary ×1

import ×1

inheritance ×1

pickle ×1