zoukankan      html  css  js  c++  java
  • Python脚本参数解析

    参数设置与获取

    import argparse
    
    parser = argparse.ArgumentParser()
    
    # 没有加横杠的参数是必传参数, 不可缺省
    parser.add_argument("train_path", help="the path of the train file", default="train.in")  
    parser.add_argument("save_path", help="the path of the saved model", default="model")
    parser.add_argument("-v","--val_path", help="the path of the validation file", default="validation.in")
    parser.add_argument("-e","--epoch", help="the number of epoch", default=100, type=int)
    parser.add_argument("-c","--char_emb", help="the char embedding file", default=None)
    parser.add_argument("-g","--gpu", help="the id of gpu, the default is 0", default=0, type=int)
    
    args = parser.parse_args()
    
    train_path = args.train_path
    save_path = args.save_path
    val_path = args.val_path
    num_epochs = args.epoch
    emb_path = args.char_emb
    

    传入参数

    python train.py train.in model -v validation.in -c char_emb -e 10 -g 2
    
    python train.py train.in model -v validation.in -e 10
    
    
  • 相关阅读:
    ovs流表机制(四)用vxlan实现多个节点的vm通信(二)
    expect
    在Scrapy中使用Selenium
    Python网络编程
    Scrapy持久化存储
    Scrapy基础
    Selenium实例
    XML和XPATH
    猫眼电影爬取
    Request模块
  • 原文地址:https://www.cnblogs.com/JohnRain/p/9252339.html
Copyright © 2011-2022 走看看