【发布时间】:2020-09-17 05:58:06
【问题描述】:
我实际上正在学习python3,但无法弄清楚为什么会这样
class Load():
def __init__(self):
print("Starting Now")
self.player = []
def player_Stats(self,filename):
with open(filename) as my_names:
names = my_names.readlines()
for one in names:
one.replace("\n","")
self.player.append(one.split[":"][0])
print(player)
print(Load.player_Stats("players.txt"))
它给了我一个错误
Traceback (most recent call last):
File "test.py", line 56, in <module>
print(Load.player_Stats("players.txt"))
TypeError: player_Stats() missing 1 required positional argument: 'filename'
我不明白为什么。
【问题讨论】:
-
您是否打算将该方法作为静态/类方法?你有它作为实例方法,但你在类本身上调用它。
标签: python python-3.x python-class