jupyter argparse 交互式 传参

2022-09-19 12:06:44

(已解决)Jupyter Notebook使用argparse报错:An exception has occurred, use %tb to see the full traceback.

parser.parse_args(args=[])# 默认参数
parser.parse_args(args=["--debug","--gpu=0","--epoch=1"])# 传入参数
import argparse

parser= argparse.ArgumentParser()

parser.add_argument('--data_dir',type=str, default='./data/',help="data directory path")
parser.add_argument('--epoch',type=int, default=3,help="number of epochs")
parser.add_argument('--gpu',type=str, default='all',help="run script on which devices")
parser.add_argument('--debug', action='store_true',help="do not log")

parser.parse_args(args=["--epoch=1","--gpu=0","--debug"])# 参数传入位置

推荐使用命令行方式运行

%run /home/run.py --epoch1 --gpu0 --debug
  • 作者:巨无霸汉堡加大
  • 原文链接:https://blog.csdn.net/weixin_43831703/article/details/124570812
    更新时间:2022-09-19 12:06:44