Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python修改sqlite数据库的表_Python_Regex_Sqlite - Fatal编程技术网

使用python修改sqlite数据库的表

使用python修改sqlite数据库的表,python,regex,sqlite,Python,Regex,Sqlite,我有一个sqlite数据库,比如test.db。它是我博客的数据库,所有博客内容都存储在这里。现在,它有一个名为“posts”的表。“帖子”包含我在博客中写的所有内容。有一个javascript在“帖子”中多次出现,我想用其他东西替换它。因此,概念是获取表“posts”,然后使用regex选择所有相似的表,然后用新表替换它。我使用python脚本从“posts”中获取数据。我想要帮助选择使用正则表达式,然后替换。以下是我的密码:- import sqlite3 conn = sqlite3.co

我有一个sqlite数据库,比如test.db。它是我博客的数据库,所有博客内容都存储在这里。现在,它有一个名为“posts”的表。“帖子”包含我在博客中写的所有内容。有一个javascript在“帖子”中多次出现,我想用其他东西替换它。因此,概念是获取表“posts”,然后使用regex选择所有相似的表,然后用新表替换它。我使用python脚本从“posts”中获取数据。我想要帮助选择使用正则表达式,然后替换。以下是我的密码:-

import sqlite3
conn = sqlite3.connect('/home/bootx/Downloads/test.db')
cur = conn.cursor()

def get_posts():
    cur.execute("SELECT * FROM posts")
    print(cur.fetchall())

get_posts()
conn.commit()
conn.close()
print "Connected fetched"

您选择打印您的帖子吗?或者是什么问题?是的,没问题。它实际上是一次打印整个表。我想先从表“posts”中打印一列,假设列名为“html”。在“html”列中,我想使用正则表达式选择一个脚本,所有脚本都是相同的,然后我想用一个新的脚本替换它。同样,我可以使用cur.execute(“从帖子中选择html”)来获取html列。但是,我不知道如何使用正则表达式来选择相同的内容。相同的行或列???列“html”中有大量数据,javascript多次出现,我想使用正则表达式来选择。