i am retrieving some results from a mysql database and they come in a form separated by brackets. I want to remove the brackets, i have used the strip function but that will only work for when i have one result to display.
The code below will only remove brackets for search results that only have one element.
@QtCore.pyqtSignature("on_pushButton_clicked()")
def searchDBnumber(self):
searchName = self.searchInput.toPlainText()
if len(searchName) != 0:
searchForName = ("""SELECT number FROM test_table WHERE name =""" + "'"+ searchName +"'")
cursor.execute(searchForName)
result = cursor.fetchall()
result = str(result).strip('[](),')
self.number.setPlainText(result)
', '.join(map(repr, result)). Can include the output ofprint(result)in your question?name =""" + "'"+ searchName +"'"when forming SQL queries. Here lies the path to lil Bobby Tables. Use placeholders and pass your arguments tocursor.execute.fetchallreturns a list of tuples (usually). You should format that usingstr.joinandstr.format(for example) to suit your needs, as pointed out by @MYGz.