我很难从另一个python脚本中的一个函数传递变量到另一个函数。我已阅读其他答案,但他们并没有真正帮助这个问题。将变量传递给另一个Python脚本
这是第一个文件欲变量发送至(为清楚起见省略了一些代码)
# TestGUI.py
from Tkinter import *
import serial
import os
class Testgui:
def __init__(self, master):
def writetoBOT(self,instruct):
ser = serial.Serial(6)
ser.baudrate = 9600
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.timeout = 1 #non-block read
ser.writeTimeout = 2 #timeout for writ
if(ser.isOpen() == False):
ser.open()
print ser.portstr # check which port was really used
ser.write(instruct)
else :
ser.write(instruct)
这是sceond文件:
# TestGUI_2.py
from TestGUI import Testgui
class Tracker:
def __init__(self):
pass
def drive(self,cords, cords1):
while(cords >= 320):
l='l'
Testgui.writetoBOT(l) # This is the problem line
类型错误:未结合的方法writetoBOT()必须使用TestGUI实例作为第一个参数调用(代替str实例)
你有2个文件,但你正在尝试执行*一个*脚本,对吧?你的描述很混乱。 –