我知道这很简单,但我不能让它工作!我没有插入,更新或选择命令的probs,让我说我有一个字典,我想用字典中的列名填充一个表,我添加一行的一行有什么问题?
##create
con = sqlite3.connect('linksauthor.db')
c = con.cursor()
c.execute('''create table linksauthor (links text)''')
con.commit()
c.close()
##populate author columns
allauthors={'joe':1,'bla':2,'mo':3}
con = sqlite3.connect('linksauthor.db')
c = con.cursor()
for author in allauthors:
print author
print type(author)
c.execute("alter table linksauthor add column '%s' 'float'")%author ##what is wrong here?
con.commit()
c.close()
Run Code Online (Sandbox Code Playgroud) 类似于我的上一个问题,但我遇到了问题让我说我有一个简单的字典,如下面但它的大,当我尝试使用下面的方法插入一个大字典我得到操作错误的c.execute(架构)太多列那么什么应该是我填充sql数据库列的替代方法?使用alter table命令并单独添加每个命令?
import sqlite3
con = sqlite3.connect('simple.db')
c = con.cursor()
dic = {
'x1':{'y1':1.0,'y2':0.0},
'x2':{'y1':0.0,'y2':2.0,'joe bla':1.5},
'x3':{'y2':2.0,'y3 45 etc':1.5}
}
# 1. Find the unique column names.
columns = set()
for _, cols in dic.items():
for key, _ in cols.items():
columns.add(key)
# 2. Create the schema.
col_defs = [
# Start with the column for our key name
'"row_name" VARCHAR(2) NOT NULL PRIMARY KEY'
]
for column in columns:
col_defs.append('"%s" REAL NULL' % column)
schema = "CREATE TABLE simple (%s);" …Run Code Online (Sandbox Code Playgroud) 没有生成 tif 图像有人看到错误吗?我没有收到任何错误。我现在看到 ghosscript 正在运行的消息,但仍然没有得到输出 tif。从输出中我现在得到“GPL Ghostscript 9.02 (2011-03-30)\n版权所有 (C) 2010 Artifex Software, Inc. 保留所有权利。\n此软件不提供任何保证:有关详细信息,请参阅文件 PUBLIC。\n”越来越近
根据评论的建议进行了编辑修改**
from subprocess import Popen, PIPE,STDOUT
output = Popen([
r'C:\Program Files (x86)\gs\gs9.02\bin\gswin32c.exe',
'-dNOPAUSE',
'-dBATCH',
'-sDEVICE=tiffg4',
'-dDEBUG',
'-r196X204',
'-sPAPERSIZE=a4',
'-sOutputFile=%s' % (r'C:\Python25\pdfmining\page.tif'),
'%s' %(r'C:\Python25\pdfmining\nca.pdf'),
],stdout=PIPE,stderr = STDOUT).communicate()[0]
Run Code Online (Sandbox Code Playgroud)