Python 如何将返回的数据从一个函数传递到另一个函数?

Python 如何将返回的数据从一个函数传递到另一个函数?,python,function,bluetooth,return,Python,Function,Bluetooth,Return,从一个可以在另一个函数中使用的函数传递返回的数据时遇到问题。这是我编写的原始代码,它工作得很好,但我想将其中一些添加到函数中。 下面是我想添加函数的代码部分。 data_received(data)功能从蓝牙服务器提取数据 我正在运行,我想将数据传递给我创建的两个函数。 我得到一个错误,“数据”没有在command=data\u received(数据)行上定义。任何帮助都将不胜感激。谢谢 def data_received(data): get_data1 = get_data2(d

从一个可以在另一个函数中使用的函数传递返回的数据时遇到问题。这是我编写的原始代码,它工作得很好,但我想将其中一些添加到函数中。

下面是我想添加函数的代码部分。 data_received(data)功能从蓝牙服务器提取数据 我正在运行,我想将数据传递给我创建的两个函数。 我得到一个错误,“数据”没有在command=data\u received(数据)行上定义。任何帮助都将不胜感激。谢谢

def data_received(data):
    get_data1 = get_data2(data)
    return get_data1

command = data_received(data) 

def auto_manual(command):
    if command == "9":
        GPIO.output(26, True)
        GPIO.output(16, False)
        #manual_mode
        #auto_mode.exit() 
        print ("Green On")
   elif command == "11":
        GPIO.output(16, True)
        GPIO.output(26, False)
        #autoMode
        #manual_mode.terminate()
        print ("Blue On")

def manual_mode(command):
    #Dpad Forward
    if command == "1":
        rouge2_manual.Forward()
    elif command == "2":
        rouge2_manual.Stop()

        #Dpad Reverse
    elif command == "3":
         rouge2_manual.Reverse()
    elif command == "4":
         rouge2_manual.Stop()

    #Dpad Left
    elif command == "5":
         rouge2_manual.Left()
    elif command == "6":
         rouge2_manual.Stop()

    #Dpad Right
    elif command == "7":
         rouge2_manual.Right()
    elif command == "8":
         rouge2_manual.Stop()

BluetoothServer(data_received)

我能够解决我的问题,谢谢:

def data_received(data):
    auto_manual(data)
    manual_mode(data)

def auto_manual(command):
    if command == "9":
       GPIO.output(26, True)
       GPIO.output(16, False)
       #manual_mode
       #auto_mode.exit() 
       print ("Green On")
   elif command == "11":
        GPIO.output(16, True)
        GPIO.output(26, False)
        #autoMode
        #manual_mode.terminate()
        print ("Blue On")

def manual_mode(command):
    #Dpad Forward
    if command == "1":
       rouge2_manual.Forward()
    elif command == "2":
         rouge2_manual.Stop()

    #Dpad Reverse
    elif command == "3":
         rouge2_manual.Reverse()
    elif command == "4":
         rouge2_manual.Stop()

    #Dpad Left
    elif command == "5":
         rouge2_manual.Left()
    elif command == "6":
         rouge2_manual.Stop()

    #Dpad Right
    elif command == "7":
         rouge2_manual.Right()
    elif command == "8":
         rouge2_manual.Stop()

BluetoothServer(data_received)
pause()

如果您想将实际参数传递给
data\u received()
,则尝试传递
数据
,该数据(显然)尚未定义(初始化或分配),错误是因为您尚未定义数据。您正在引用“数据”,而没有告诉Python“数据”是什么。