2016-02-21 84 views
0

这是我的代码的精简版本。 当我试着执行它时,我得到:Python 3:我在这里做错了什么?

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) 

我在做什么错?

+0

...嗯,这发生在累得代码:)谢谢 – deajan

回答

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 
相关问题