小编use*_*071的帖子

如何将列添加到sqlite3 python?

我知道这很简单,但我不能让它工作!我没有插入,更新或选择命令的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)

python sqlite

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

如何在sqlite3中插入几千列?

类似于我的上一个问题,但我遇到了问题让我说我有一个简单的字典,如下面但它的大,当我尝试使用下面的方法插入一个大字典我得到操作错误的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)

python sqlite

3
推荐指数
1
解决办法
1769
查看次数

没有得到任何输出或错误 Ghostscript python

没有生成 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)

python ghostscript

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

标签 统计

python ×3

sqlite ×2

ghostscript ×1