Python中強大的命令列庫click入門教程,pythonclick

來源:互聯網
上載者:User

Python中強大的命令列庫click入門教程,pythonclick

前言

我們的遊戲資源處理工具是Python實現的,功能包括csv解析,UI材質處理,動畫資源解析、批處理,Androd&iOS自動打包等功能。該項目是由其他部門繼承過來的,由於絕大部分代碼不符合我們的業務需求,所以進行了大重構。刪除了所有業務代碼,僅保留了python代碼架構。項目中命令列參數解析是自己實現的,極其不優雅,也忍了這麼久。打算找時間用click重寫。所以最近學習了click,下面本文的內容是click的入門教程,初學者們可以來一起學習學習。

官網鏡像地址: http://click.uoota.com/6/

支援:

  1. 命令的任意嵌套
  2. 自動產生協助資訊
  3. 支援在運行時子命令的消極式載入

安裝方法是使用 pip:

pip install click

下面一小段代碼是其官方首頁的例子,貼出來下:

import click @click.command()@click.option('--count', default=1, help='Number of greetings.')@click.option('--name', prompt='Your name',    help='The person to greet.')def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count):  click.echo('Hello %s!' % name) if __name__ == '__main__': hello()

運行:

$ python hello.py --count=3Your name: JohnHello John!Hello John!Hello John!

查看協助資訊:

$ python hello.py --helpUsage: hello.py [OPTIONS]  Simple program that greets NAME for a total of COUNT times. Options: --count INTEGER Number of greetings. --name TEXT  The person to greet. --help   Show this message and exit.

總結

以上就是介紹Python中命令列工具click的安裝與使用的全部內容了,希望本文的內容對大家學習或者使用python能帶來一定的協助,如果有疑問大家可以留言交流。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.