I am doing a Python course, and the current task is to get information from the database, add it to the text box, and then create an HTML file from the contents inside the text box.
Everything works fine, with line breaks exactly as I entered them into the database. The only problem is that "{{and"}} "is added around the text after it is received from the database. Therefore, I turn the text into a string and a fragment that is used with [3: -4]. But then, since now it string, now it literally writes "\ n" to the text when entering into the text field.
In any case, to cut off the brackets, DO NOT include the text "\ n", but do you keep the lines?
Here is what the text field is displayed before I turn it into a string and a fragment:
{{This is my text! It looks very clean because it has line breaks. Cool!}}
And after I make it a line and cut the ends:
This is my text! \ N \ nCorticles have disappeared, but now you can see the queue code. \ n \ nLame!
Can I have the best of both worlds? Here is my code:
def getContent(self):
c.execute("SELECT HTML FROM Content WHERE conName ='{}'".format(self.contentBox.get()))
fetch = (c.fetchall())
return str(fetch)[3:-4]
def setContent(self):
self.clear()
combo = self.getContent()
self.text_body.insert(END,combo)
source
share