如何对特使使用通配符

2024-05-15 22:08:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着通过KennethReitz的特使包运行这个命令:

$ sqlite3 foo.db 'select * from sqlite_master' 

我试过了:

^{pr2}$

还有这个:

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

附加的引用和转义似乎没有帮助。有什么建议吗?在

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

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

请注意,这是一个精心设计的示例,我想发布的大多数unixshell命令并不仅仅是一个简单的选择,可以通过SQLAlchemy轻松地完成。在


Tags: runfrom命令mastercmddbsqlitefoo
2条回答

这在envoy中不起作用,因为特使将命令拆分并传递给子进程。即使您尝试使用subprocess.Popen(command, shell = False),也会得到sqlite3终端。subprocess和{}都没有解决这个问题,如果你能在envoy打开一个问题,我会很高兴的,因为我正在为它做贡献,我会考虑这个问题。在

您可以使用subprocess

from subprocess import check_output as qx

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

sqlite3模块:

^{pr2}$

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

import envoy

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

相关问题 更多 >