python运行脚本参数从几开始_从另一个脚本导入python脚本并使用参数运行它

I have a python script which has been packaged up as a command line script (dbtoyaml.py in Pyrseas since you ask).

I am running another python script from which I want to call this script. Is there no way to import the module and artificially populate the required arguments from my second script to avoid changing any of the pyrseas code at all?

from pyrseas import dbtoyaml

-- My initial script, which also takes arguments

dbtoyaml.main(['-m','-H MYHOSTNAME' .... other options])

Hasn't yet worked for me.

I get a strange error:

usage: checkSchemaChanges.py [-h] [-H HOST] [-p PORT] [-U USERNAME] [-W]

[-c CONFIG] [-r REPOSITORY] [-o OUTPUT]

[--version] [-m] [-O] [-x] [-n SCHEMA]

[-N SCHEMA] [-t TABLE] [-T TABLE]

dbname

checkSchemaChanges.py: error: unrecognized arguments: MYHOSTNAME mydatabaseuser

Which is a mixture of my new script (checkSchemaChanges.py, and MYHOSTNAME and mydatabaseuser at the bottom) and the parameters from dbtoyaml, which are all correct.

Could it be the double set of parameters which is confusing argparse?

解决方案

this seems like not the best way to do it but you can probably set sys.argv

import sys

sys.argv += ['-m','-H MYHOSTNAME' .... other options]

from pyrseas import dbtoyaml

dbtoyaml.main()

but really I have no idea what dbtoyaml.py lookslike or is

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值