E
E
espelioser2018-05-19 00:04:58
Python
espelioser, 2018-05-19 00:04:58

What type of variable is being passed and how can this line be corrected?

Error occurs:
Traceback (most recent call last):
File "main.py", line 35, in printText self.textBrowser.append
(response)
TypeError: QTextEdit.append(str): argument 1 has unexpected type 'Statement'
:

import sys  
from PyQt5 import QtWidgets
import design  # файл дизайна
import os
import re
import datetime
import time
import sys
from pygame import mixer
from gtts import gTTS
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot


class ExampleApp(QtWidgets.QMainWindow, design.Ui_MainWindow):
 def __init__(self):
  super().__init__()
  self.setupUi(self)  
  self.pushButton.clicked.connect(self.printText)
 def printText(self):
  dannie = self.textEdit.toPlainText()
  self.textBrowser.append(dannie)
  mp3_nameold='111'
  mp3_name = "1.mp3"
  mixer.init()
  bot = ChatBot('Test')

  conv = open('chat.txt','r').readlines()

  bot.set_trainer(ListTrainer)
  bot.train(conv)
  while True:
     response = bot.get_response(dannie)
     str(response)
     self.textBrowser.append(response)
    
    
def main():
    app = QtWidgets.QApplication(sys.argv)  
    window = ExampleApp()  
    window.show() 
    app.exec_()  

    
if __name__ == '__main__': 
    main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Simon Osipov, 2018-05-19
@SimonOsipov

Let's take a look at
What does it do? That's right, nothing. Simplified text - the computer led to the response string type and did not save it anywhere.
There are two options:
1) self.textBrowser.append(str(response)) - preferred. The cast happens immediately with append.
2) response = str(response) - casting a variable to a string type and assigning it to itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question