[英]TypeError: read_csv() takes from 0 to 1 positional arguments but 2 were given
What am I missing here?我在这里缺少什么? I have tried looking at the code but I do not know where the extra positional argument is located at,我曾尝试查看代码,但我不知道额外的位置参数位于何处,
def read_csv(path: str = None) -> List[List] :
lead = Path(__file__).parent / f'../data/{path}'
entries = []
print('Reading dataset...')
with open(lead, 'r') as csvfile:
video_reader = csv.reader(csvfile)
for row in video_reader:
entries.append(row)
return print(entries)
Traceback (most recent call last):
File "C:/Users/MEDIAMARKT/Desktop/booking/__main__.py", line 15, in <module>
gui = GUI()
File "C:\Users\MEDIAMARKT\Desktop\booking\gui.py", line 22, in init
self.upload_data()
File "C:\Users\MEDIAMARKT\Desktop\booking\gui.py", line 84, in upload_data
self.booking.read_csv(path)
TypeError: read_csv() takes from 0 to 1 positional arguments but 2 were given
Your error is elsewhere, not in the snippet provided, since as a standalone function, that code should work fine.您的错误在其他地方,而不是在提供的代码段中,因为作为独立函数,该代码应该可以正常工作。
Looking at your traceback, you've introduced classes, so reading your error看看你的回溯,你已经引入了类,所以阅读你的错误
2 were given 2 被给予
When you call a class function, the instance of that class is always supplied as a parameter当您调用类函数时,该类的实例始终作为参数提供
example例子
class Foo:
def bar(self, other=None): # self is a required argument for instance methods
pass
xyz = 'something'
booking = Foo()
booking.bar() # 1 parameter provided - the instance itself
booking.bar(xyz) # 2 parameters provided - the instance and the string
So, to fix your function, you need to add the self parameter, even if you don't plan on using it.因此,要修复您的函数,您需要添加 self 参数,即使您不打算使用它。
Before, the path
variable you used wasn't actually a string, so the type checker should have been throwing an error as well之前,您使用的path
变量实际上不是字符串,因此类型检查器也应该抛出错误
class Booking():
def read_csv(self, path:str = None) -> List[List]:
# TODO
return []
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.