I have a database:

As you can see in the 'desc' column, the text is of variable length (meaning no two strings I pull from this database are going to be of the same length). I will eventually add many more entries to this database, but this is what I'm testing with and starting with at the moment.
Right now, I have the following python code to grab these blocks of string and display them:
cmd = input(Enter command:)
sql = "SELECT cmd,`desc` FROM table WHERE cmd = '"+ cmd +"'"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print("Command: "+ row[0] +":\n")
print("Description: "+ row[1][:40] +"\n")
if (len(row[1]) > 40):
print(row[1][40:85])
if (len(row[1]) > 85):
print(row[1][85:130])
if (len(row[1]) > 130):
print(row[1][130:165])
if (len(row[1]) > 165):
print(row[1][165:])
The splitting here works to an extent, for example:
Command: close:
Description: This command will create a 'close' butto
n in the message window for the invoking char
acter. If no window is currently on screen, t
he script execution will end.
As you can see with the example above of the output, the split causes some characters to get cut off in mid word. Given the fact that the strings could be of any length between say...20 total characters and up to 190ish, and I want to split the string into chunks of say...8 words each because of space constraints, how would I go about doing this?
cursor.execute('select * from commands where cmd=?', (cmd,)). You don't need to callcursor.fetchall()you could iterate over it directly:for row in cursor: ...