栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

docopt 使用手册

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docopt 使用手册

文章目录
  • 前言
  • 版本
  • 例子


前言

这个例子很简单,但是对我来说够用,日后可以基于这个例子拓展

版本

docopt: 0.6.2
python: 3.6

例子

注意要写在import 前面, 否则报错。

"""
Usage:
  vocab.py [options] TRAIN_SET_SRC TRAIN_SET_TGT VOCAB_FILE

Options:
    -h --help                  Show this screen.
    --size-src INT             src vocab size [default: 50000]
    --size-tgt INT             tgt vocab size [default: 50000]
    --freq-cutoff INT          frequency cutoff [default: 2]
    --vocab-class STR          the class name of used Vocab class [default: Vocab]
"""

必选参数:
TRAIN_SET_SRC TRAIN_SET_TGT VOCAB_FILE

可选参数:
-h --help Show this screen.
–size-src INT src vocab size [default: 50000]
–size-tgt INT tgt vocab size [default: 50000]
–freq-cutoff INT frequency cutoff [default: 2]
–vocab-class STR the class name of used Vocab class [default: Vocab]

执行方法:

python ../vocab.py ../samples/train/train.spl.src          ../samples/train/train.txt.tgt          ../samples/dic/python_dic.json

结果:

{'--freq-cutoff': '2',
 '--help': False,
 '--size-src': '50000',
 '--size-tgt': '50000',
 '--vocab-class': 'Vocab',
 'TRAIN_SET_SRC': '../samples/train/train.spl.src',
 'TRAIN_SET_TGT': '../samples/train/train.txt.tgt',
 'VOCAB_FILE': '../samples/dic/python_dic.json'}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/299753.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号