首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用多个参数执行python脚本并导出常量值?

如何使用多个参数执行python脚本并导出常量值?
EN

Stack Overflow用户
提问于 2022-05-11 13:23:21
回答 1查看 82关注 0票数 0

我在脚本环境中很新奇,这一定是个愚蠢的问题,但我找不到答案。

我想用一个github存储库中的几个参数编译一个.py程序。他们解释了如何编译它,但我不知道如何将这样的许多参数传递到命令行。

代码语言:javascript
复制
export scale=6
export TRAIN_FILE=sample_data/pre/100.txt
export TEST_FILE=sample_data/pre/100.txt
export SOURCE=PATH_TO_REPO
export OUTPUT_PATH=output$scale

python run_train.py \
    --output_dir $OUTPUT_PATH \
    --model_type=dna \
    --name=triq$scale \
    --config_name=$SOURCE/src/config.json \
    --do_train \
    --train_data_file=$TRAIN_FILE \
    --do_eval \
    --eval_data_file=$TEST_FILE \
    --gradient_accumulation_steps 25 \
    --per_gpu_train_batch_size 10 \
    --per_gpu_eval_batch_size 6 \

我不知道如何传递/编译这些输入。一些暗示?

一切都会感激的!

EN

回答 1

Stack Overflow用户

发布于 2022-05-11 13:32:05

代码语言:javascript
复制
import argparse
def get_inputs():     
    parser = argparse.ArgumentParser(description="The script is used for extracting cell info from the lib!")
    parser.add_argument('--output_dir',help="This switch is used to fetch the grepped raw data file\n")
    args = parser.parse_args()
    return args
args=get_inputs()


a = '''[WARN] : No sufficient inputs!!!

usage: post_process.py [-h] [--output_dir OUTPUT_PATH] 

The script is used for extracting cell info from the lib!

optional arguments:
  -h, --help            show this help message and exit
  --output_dir OUTPUT_PATH 
'''

if args.output_dir  is None:
    print(a)
    exit()

若要在脚本中使用路径:

rawdata_path=args.output_dir

您可以阅读更多关于You解析的内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72201858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档