Python3:我做错什么了?

2024-10-03 06:29:51 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我代码的精简版本。 当我尝试执行它时,我得到:

Traceback (most recent call last): File "test.py", line 16, in value = oss.get() TypeError: get() takes 0 positional arguments but 1 was given

import os

class OsyncStateSerial():
        """Reads and writes current state serial for local replica"""

        def __init__(self, oss_file):
                if os.path.exists(oss_file):
                        pass
        def ranget():
                return 1

        def ranset():
                return 0

oss = OsyncStateSerial("somefile")
value = oss.ranget()
print(value)

我做错什么了?你知道吗


Tags: 代码版本mostgetreturnvalueosdef
1条回答
网友
1楼 · 发布于 2024-10-03 06:29:51

您需要在类方法中包含参数self

import os

class OsyncStateSerial():
        """Reads and writes current state serial for local replica"""

        def __init__(self, oss_file):
                if os.path.exists(oss_file):
                        pass
        def ranget(self):
                return 1

        def ranset(self):
                return 0

oss = OsyncStateSerial("somefile")
value = oss.ranget()
print(value)

输出

1

相关问题 更多 >