Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么这个python函数有两个参数?_Python_Mindstorms_Ev3 - Fatal编程技术网

为什么这个python函数有两个参数?

为什么这个python函数有两个参数?,python,mindstorms,ev3,Python,Mindstorms,Ev3,输出: from ev3dev.ev3 import * from time import sleep ml = LargeMotor('outB') mr = LargeMotor('outC') ts = TouchSensor() cs = ColorSensor() us = UltrasonicSensor() cs.mode = 'COL-REFLECT' us.mode = 'US-DIST-CM' def motorenStop(stopaction): ml

输出:

from ev3dev.ev3 import *

from time import sleep


ml = LargeMotor('outB')
mr = LargeMotor('outC')
ts = TouchSensor()
cs = ColorSensor()
us = UltrasonicSensor()

cs.mode = 'COL-REFLECT'
us.mode = 'US-DIST-CM'


def motorenStop(stopaction):
    ml.stop(stop_action=stopaction)
    mr.stop(stop_action=stopaction)


def motorenRun(speed_sp, time_sp = None, stop_action = None):
    if time_sp is not None and stop_action is not None:
        ml.run_timed(time_sp=time_sp, speed_sp=speed_sp, stop_action=stop_action)
        mr.run_timed(time_sp=time_sp, speed_sp=speed_sp, stop_action=stop_action)
    else:
        ml.run_forever(speed_sp)
        mr.run_forever(speed_sp)




def drive():

    while 1==1:
        motorenRun(300)
回溯(最近一次呼叫最后一次):
文件“/home/robot/helloworld/main.py”,第21行,在
驱动器()
文件“/home/robot/helloworld/drive.py”,第35行,在驱动器中
摩托伦(300)
文件“/home/robot/helloworld/drive.py”,第26行,在motorenRun中
ml.run_永久(速度_sp)
TypeError:run_forever()接受1个位置参数,但给出了2个
我曾经尝试用python运行我的EV3,现在我遇到了一个问题,两个参数被传递给一个函数。我寻找我的问题,但我找不到任何解决办法。如何修复此错误?

是一个默认情况下不接受任何参数的函数。但是,您会注意到它有一个参数
**kwargs
。这意味着您可以传入可选的命名参数,如下所示:

Traceback (most recent call last):
  File "/home/robot/helloworld/main.py", line 21, in <module>
    drive()
  File "/home/robot/helloworld/drive.py", line 35, in drive
    motorenRun(300)
  File "/home/robot/helloworld/drive.py", line 26, in motorenRun
    ml.run_forever(speed_sp)
TypeError: run_forever() takes 1 positional argument but 2 were given
试试看是否有效

ml.run_forever(speed_sp=speed_sp)