在使用rasa开发聊天机器人时,我遇到了一个问题。
我正在尝试在rasa操作文件中调用自定义函数。但是我收到一条错误消息,提示“未定义名称'areThereAnyErrors'”
这是我的动作课。我想从运行方法调用areThereAnyErrors函数。有人可以帮忙解决这个问题吗?
ActionDayStatus(Action)类:
def areThereAnyErrors(procid):
errormessagecursor = connection.cursor()
errormessagecursor.execute(u"select count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T = :messageT",{"procid": procid, "messageT": 'E'})
counts = errormessagecursor.fetchone()
errorCount = counts[0]
print("error count is {}".format(errorCount))
if errorCount == 0:
return False
else:
return True
def name(self):
return 'action_day_status'
def run(self, dispatcher, tracker, domain):
import cx_Oracle
import datetime
# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
conn_str = dbconnection
connection = cx_Oracle.connect(conn_str)
cursor = connection.cursor()
dateIndicator = tracker.get_slot('requiredDate')
delta = datetime.timedelta(days = 1)
now = datetime.datetime.now()
currentDate = (now - delta).strftime('%Y-%m-%d')
print(currentDate)
cursor = connection.cursor()
cursor.execute(u"select * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})
all_files = cursor.fetchall()
total_number_of_files = len(all_files)
print("total_number_of_files are {}".format(total_number_of_files))
答案 0 :(得分:0)
其中一位知识分子给出的答案:
https://realpython.com/instance-class-and-static-methods-demystified/决定是否要使用静态方法,类方法或实例方法并适当地调用它。另外,当您在函数中使用连接时,它应该是成员变量或传递给方法。您没有self作为参数,因此您可能打算将其作为静态方法使用-但是您没有这样创建它