美文网首页python交流学习
想知道Python中的那个库用于生成命令行界面的内容?Pytho

想知道Python中的那个库用于生成命令行界面的内容?Pytho

作者: 78c40b03ee4e | 来源:发表于2019-02-21 16:01 被阅读3次

    前言

    Python之所以强大,是因为它拥有各种各样的库,今天为大家介绍一款酷酷的库,Python Fire 是 Google 开源的一个可从任何 Python 代码自动生成命令行接口(CLI)的库。

    • Python Fire 是一种在 Python 中创建 CLI 的简单方法。

    • Python Fire 是开发和调试 Python 代码的有用工具。

    • Python Fire 帮助探索现有代码或将其他人的代码转换为CLI。

    • Python Fire 使 Bash 和 Python 之间的转换更为容易。

    • Python Fire 通过使用你需要导入和创建的模块和变量来设置 REPL,使得使用 Python REPL 更容易。

    简易示例:

    import fire
    
    class Calculator(object):
      """A simple calculator class."""
    
      def double(self, number):
        return 2 * number
    
    if __name__ == '__main__':
      fire.Fire(Calculator)
    

    然后,你可以运行:

    python calculator.py double 10  # 20
    python calculator.py double --number=15  # 30
    

    小编推荐一个学python的学习qun 740322234
    无论你是大牛还是小白,是想转行还是想入行都可以来了解一起进步一起学习!裙内有开发工具,很多干货和技术资料分享!

    相关文章

      网友评论

        本文标题:想知道Python中的那个库用于生成命令行界面的内容?Pytho

        本文链接:https://www.haomeiwen.com/subject/ectdyqtx.html