折腾:
【已解决】给crifan的gitbook的template添加部署时更新github.io的README
期间,需要运行python脚本期间,从命令行中传入参数。
python command line arguments
1 2 3 4 5 6 7 8 9 | 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中调用试试
【总结】
后来测试:
1 2 3 4 5 6 7 8 9 | 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中触发的)命令行运行
1 2 3 4 5 | 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 ; |
输出:
1 2 | args=Namespace(localGithubIoPath= '/Users/limao/dev/crifan/crifan.github.io' ) localGithubIoPath= /Users/limao/dev/crifan/crifan .github.io |
即可。
转载请注明:在路上 » 【已解决】Python中解析命令行传入的参数