Python 3.x python重新打开并将数据写入现有文件(文件名由用户先前的输入提供)
我正在使用python Rasa堆栈。在一个类(Python 3.x python重新打开并将数据写入现有文件(文件名由用户先前的输入提供),python-3.x,io,Python 3.x,Io,我正在使用python Rasa堆栈。在一个类(ActionAgree)中,例如在下面的代码中,我使用用户输入(ID)作为txt文件名。然后,数据将被写入这个txt文件。 在另一个类(ActionTopic)中,我想再次打开此文件并将一些数据写入其中。我的问题是如何达到这个目的 我的部分代码: class ActionAgree(FormAction): def name(self): return 'action_agree' def submit(self
ActionAgree
)中,例如在下面的代码中,我使用用户输入(ID
)作为txt文件名。然后,数据将被写入这个txt文件。
在另一个类(ActionTopic
)中,我想再次打开此文件并将一些数据写入其中。我的问题是如何达到这个目的
我的部分代码:
class ActionAgree(FormAction):
def name(self):
return 'action_agree'
def submit(self, dispatcher, tracker, domain):
#this is to get the student ID as his/her input
booking = agree_info.save(tracker.latest_message.get("text"))
put channel: " + str(lic_log))
...
...
...
#using user input to create a txt file
indexFile_senderid = open(str(booking) + '.txt', 'a+', encoding='utf-8')
indexFile_senderid.write('ActionAgree_' + 'student ID: ' + tracker.latest_message.get("text") + str('\n\n'))
indexFile_senderid.close()
return[]
class ActionTopic(FormAction):
def name(self):
return 'action_topic'
def submit(self, dispatcher, tracker, domain):
...
...
return[]
我自己解决了。我发现我可以使用插槽值(用户输入)。所以我在另一个类中称之为slot值