从文本块中切出最后一个单词的最佳方法是什么?
我能想到
我目前正在采取方法#1,但我不知道如何连接列表...
content = content[position-1:position+249] # Content
words = string.split(content, ' ')
words = words[len[words] -1] # Cut of the last word
Run Code Online (Sandbox Code Playgroud)
任何代码示例都非常感谢.
我正在用 Python 执行一个简单的查询,但它执行时似乎什么也没发生,就好像它跳过了执行一样。
这是代码:
def somefunction(search_query):
from django.db import connection, transaction
search_query = search_query.strip()
cursor = connection.cursor()
rows = cursor.execute("INSERT INTO searches (query) VALUES ('"+ search_query +"')")
Run Code Online (Sandbox Code Playgroud)
查询没有任何问题,我没有收到错误消息或什么也没有,它只是不起作用!
有任何想法吗?