小编qwe*_*rty的帖子

Python:切断句子的最后一个字?

从文本块中切出最后一个单词的最佳方法是什么?

我能想到

  1. 将其拆分为一个列表(按空格)并删除最后一项,然后重新合并列表.
  2. 使用正则表达式替换最后一个单词.

我目前正在采取方法#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 split concatenation cpu-word text-segmentation

45
推荐指数
3
解决办法
7万
查看次数

Python/MySQL:查询执行但没有任何反应?

我正在用 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)

查询没有任何问题,我没有收到错误消息或什么也没有,它只是不起作用!

有任何想法吗?

python mysql django

2
推荐指数
1
解决办法
1421
查看次数