Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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 在SQLite3数据库中存储带引号的推文_Python_Twitter_Sqlite - Fatal编程技术网

Python 在SQLite3数据库中存储带引号的推文

Python 在SQLite3数据库中存储带引号的推文,python,twitter,sqlite,Python,Twitter,Sqlite,我正在使用json从web加载推文 import urllib2, json, sqlite3 wFD = urllib2.urlopen('http://rasinsrv07.cstcis.cti.depaul.edu/CSC455/Twitter_2013_11_12.txt') blankLines = 0 goodLines = 0 numLines = 10000 while numLines > 0: line = wFD.readline() numLines

我正在使用json从web加载推文

import urllib2, json, sqlite3
wFD = urllib2.urlopen('http://rasinsrv07.cstcis.cti.depaul.edu/CSC455/Twitter_2013_11_12.txt')
blankLines = 0
goodLines = 0
numLines = 10000
while numLines > 0:
    line = wFD.readline()
    numLines = numLines - 1
    try:    
         tweets.append(json.loads(line))
         goodLines = goodLines+1
    except:
        blankLines = blankLines + 1
blankLines
goodLines
我必须检查整个tweet的长度,然后使用SQLite3将其作为一个大条目存储在数据库的表中

SingleTable = """Create table SingleTable
            (tweet varchar(8038)
            );"""
c.execute("drop table if exists SingleTable")            
c.execute(SingleTable)

len_strTwt = 0
for tweet in tweets:
    str_tweet = str(tweet)
    c.execute("insert into SingleTable values (?)", (str_tweet))
    if len_strTwt < len(str_tweet):
        len_strTwt = len(str_tweet)
len_strTwt
SingleTable=“”创建表SingleTable
(tweet varchar(8038)
);"""
c、 执行(“如果存在单表,则删除表”)
c、 执行(单表)
len_strTwt=0
对于推文中的推文:
str_tweet=str(tweet)
c、 执行(“插入到单表值(?),(str_tweet))
如果len_strtweet

当我尝试存储它时,由于太多的双引号和单引号,我无法存储它。我不知道如何在这里使用excape符号来将其存储在数据库中。任何帮助都将不胜感激。谢谢。

您需要一个额外的逗号来告诉Python您想要一个元组:

c.execute("insert into SingleTable values (?)", (str_tweet,))
如果没有逗号,您将得到一个普通字符串,它将被
execute
解释为一个字符序列,即每个字符将是一个参数值

请注意,SQLite默认情况下不检查列的长度