这是我的代码的精简版本。 当我尝试执行它时,我得到:
追踪(最近一次通话): 文件“test.py”,第16行,in value = oss.get() TypeError:get()接受0个位置参数,但是给出了1个
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)
我做错了什么?
答案 0 :(得分:2)
您需要在类方法中包含参数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