栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

(半)自动生成函数的argparsers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

(半)自动生成函数的argparsers

你尝试过普拉克吗?

docs中的示例:

# dbcli.pyimport placfrom sqlalchemy.ext.sqlsoup import SqlSoup@plac.annotations(    db=plac.Annotation("Connection string", type=SqlSoup),    header=plac.Annotation("Header", 'flag', 'H'),    sqlcmd=plac.Annotation("SQL command", 'option', 'c', str, metavar="SQL"),    delimiter=plac.Annotation("Column separator", 'option', 'd'),    scripts=plac.Annotation("SQL scripts"),    )def main(db, header, sqlcmd, delimiter="|", *scripts):    "A script to run queries and SQL scripts on a database"    yield 'Working on %s' % db.bind.url    if sqlcmd:        result = db.bind.execute(sqlcmd)        if header: # print the header yield delimiter.join(result.keys())        for row in result: # print the rows yield delimiter.join(map(str, row))    for script in scripts:        db.bind.execute(open(script).read())        yield 'executed %s' % scriptif __name__ == '__main__':    for output in plac.call(main):        print(output)

输出:

usage: dbcli.py [-h] [-H] [-c SQL] [-d |] db [scripts [scripts ...]]A script to run queries and SQL scripts on a databasepositional arguments:  db         Connection string  scripts    SQL scriptsoptional arguments:  -h, --help show this help message and exit  -H, --header          Header  -c SQL, --sqlcmd SQL  SQL command  -d |, --delimiter |   Column separator


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441276.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号