Python 官方文档:入门教程 => 点击学习
目录简介优势历史攻略安装案例简介 python Fire是谷歌开源的一个第三方库,用于从任何Python对象自动生成命令行接口(CLI),可用于如快速拓展成命令行等形式。 优势 Py
python Fire是谷歌开源的一个第三方库,用于从任何Python对象自动生成命令行接口(CLI),可用于如快速拓展成命令行等形式。
Python Fire是一个库,用于从任何Python对象自动生成命令行接口(CLI)。
PythonFire是在Python中创建CLI的简单方法。
PythonFire是开发和调试Python代码的有用工具。
Python Fire有助于探索现有代码或将其他人的代码转换为CLI。
PythonFire使Bash和Python之间的转换更加容易。
Python Fire通过使用已经导入和创建的模块和变量设置REPL,
使用PythonREPL变得更容易。
Python:解析命令行参数
Python:装饰器click处理解析命令行参数
pip install fire
# -*- coding: utf-8 -*-
# time: 2022/10/22 10:30
# file: fire_demo.py
# 公众号: 玩转测试开发
import fire
import datetime
import asyncio
def hello(name="World"):
print(f"Hello {name}!")
class Calculator(object):
"""A simple calculator class."""
def double(self, number):
return 2 * number
async def f1(name):
await asyncio.sleep(0.5)
print(f"{str(datetime.datetime.now())}: {name} run.")
def main(workers, loop=1, name="tom"):
for i in range(loop):
tasks = [f1(name) for i in range(workers)]
asyncio.run(asyncio.wait(tasks))
if __name__ == '__main__':
# fire.Fire(hello)
# fire.Fire(Calculator)
fire.Fire(main)
hello函数运行结果:
python hello.py # Hello World!
python hello.py --name=Tom # Hello Tom!
python hello.py --help # Shows usage infORMation.
double函数运行结果:
main函数运行结果:
即:通过fire模块,可以快速高效的生成命令行接口,大大提高开发效率,不愧为高star项目,比click模块好用不少。
到此这篇关于Python fire模块(最简化命令行生成工具)的使用教程详解的文章就介绍到这了,更多相关Python fire模块内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Pythonfire模块(最简化命令行生成工具)的使用教程详解
本文链接: https://www.lsjlt.com/news/120845.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0