最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Python中解析命令行传入的参数

Python crifan 1249浏览 0评论
折腾:
【已解决】给crifan的gitbook的template添加部署时更新github.io的README
期间,需要运行python脚本期间,从命令行中传入参数。
python command line arguments
Python Command Line Arguments – Real Python
16.4. argparse — Parser for command-line options, arguments and sub-commands — Python 3.3.7 documentation
Python – Command Line Arguments – Tutorialspoint
import argparse

parser = argparse.ArgumentParser(description='Update crifan.github.io README.md')
parser.add_argument(‘--localGithubIoPath', type=str, help='local github.io path')


args = parser.parse_args()
localGithubIoPath = args.localGithubIoPath
print("localGithubIoPath=%s" % localGithubIoPath)
去makefile中调用试试
【总结】
后来测试:
import argparse

parser = argparse.ArgumentParser(description='Update crifan.github.io README.md')
parser.add_argument('--localGithubIoPath', type=str, help='local github.io path')

args = parser.parse_args()
print("args=%s" % args)
localGithubIoPath = args.localGithubIoPath
print("localGithubIoPath=%s" % localGithubIoPath)
(makefile中触发的)命令行运行
        if [ true == true ]; then \
                python /Users/limao/dev/crifan/gitbook/gitbook_template/common/tools/update_crifan_github_io_readme.py --localGithubIoPath /Users/limao/dev/crifan/crifan.github.io; \
        else \
                echo "Ignored update README.md before commit mobile_network_evolution_history to github.io"; \
        fi;
输出:
args=Namespace(localGithubIoPath='/Users/limao/dev/crifan/crifan.github.io')
localGithubIoPath=/Users/limao/dev/crifan/crifan.github.io
即可。

转载请注明:在路上 » 【已解决】Python中解析命令行传入的参数

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.164 seconds, using 22.10MB memory