如何在Envoy中使用通配符 [英] How to use wildcards with Envoy

查看:163
本文介绍了如何在Envoy中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过KennethReitz的Envoy软件包运行此命令:

I'm trying to run this command through KennethReitz's Envoy package:

$ sqlite3 foo.db 'select * from sqlite_master' 

我已经尝试过了:

r = envoy.run("sqlite3 foo.db 'select * from sqlite_master'")
sqlite3: Error: too many options: "*"

和这个:

r = envoy.run(['sqlite3', 'foo.db', 'select * from sqlite_master'])
AttributeError: 'NoneType' object has no attribute 'returncode'

附加报价&转义似乎没有帮助.有什么建议吗?

additional quoting & escaping doesn't seem to help. Any suggestions?

仅供参考:这是我现在要做的:

FYI: This is what I had to do for now:

cmd = "sqlite3 %(database)s 'select * from sqlite_master'" % locals()
os.system(cmd)

请注意,这是一个人为的示例,我要发出的大多数unix shell命令不仅是可以通过SQLAlchemy轻松完成的简单选择.

Note that this is a contrived example, and that most of the unix shell commands that I'd like to issue aren't just a simple select that could be easily done via SQLAlchemy.

推荐答案

您可以使用subprocess:

from subprocess import check_output as qx

output = qx(['sqlite3', 'foo.db', 'select * from sqlite_master'])
print output

sqlite3模块:

import sqlite3

conn = sqlite3.connect('foo.db')
for row in conn.execute('select * from sqlite_master'):
    print row

如果您仍然想使用envoy,则可以将其修复为:

If you still want to use envoy then you could fix it as:

import envoy

r = envoy.run([["sqlite3", "foo.db", "select * from sqlite_master"]])
print r.std_out

这篇关于如何在Envoy中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆