首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python中函数的问题(TypeError: touch_detect()接受0个位置参数,但给出了1个)

python中函数的问题(TypeError: touch_detect()接受0个位置参数,但给出了1个)
EN

Stack Overflow用户
提问于 2021-07-20 20:42:24
回答 1查看 18关注 0票数 0

我在尝试运行python代码时遇到了一个问题

问题就在这里

代码语言:javascript
复制
File "touch_detect.py", line 24, in <module>
   touch_detect()
   File "touch_detect.py", line 19, in touch_detect
   is_touching, certainty = touch_detect(source.image)
   TypeError: touch_detect() takes 0 positional arguments but 1 was given

下面是我的代码

代码语言:javascript
复制
import pytouch
from pytouch.handlers import ImageHandler
from pytouch.sensors import DigitSensor
from pytouch.tasks import TouchDetect
from pytouch import PyTouchZoo, sensors

def touch_detect():
     source = ImageHandler("/home/../Documents/Digit2.png")

     # initialize with task defaults
     pt = pytouch.PyTouch(DigitSensor, tasks=[TouchDetect])
     is_touching, certainty = pt.TouchDetect(source.image)

     # initialize with custom configuration of TouchDetect task
     touch_detect=TouchDetect(DigitSensor,zoo_model="touchdetect_resnet18")

     is_touching, certainty = touch_detect(source.image)
     print(f"Is touching? {is_touching}, {certainty}")


if __name__ == "__main__":
     touch_detect()

这段代码实际上是用于触觉感知的,并不是我写的代码,它被作为示例包含在一个名为pytouch的开源库中,该库用于几个应用程序,如我正在使用的触摸检测

EN

回答 1

Stack Overflow用户

发布于 2021-07-20 20:52:52

问题出在以下部分:

代码语言:javascript
复制
# initialize with custom configuration of TouchDetect task
touch_detect=TouchDetect(DigitSensor,zoo_model="touchdetect_resnet18")

is_touching, certainty = touch_detect(source.image)

您使用一个参数(source.image)递归地调用touch_detect,但该函数不接受任何参数。

我假设您想在TouchDetect对象上调用一个方法,但是包含该对象的变量的名称与该方法的名称相同。我建议使用不同的变量名,或者更改方法的名称

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68455083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档