【转】Python之FLAGS用法

【转】https://www.cnblogs.com/huangshiyu13/p/8415665.html

flag_test.py

测试:python flag_test.py --gpu=abc

import sys, os
from absl import app
from absl import flags

FLAGS = flags.FLAGS
flags.DEFINE_string('gpu', None, 'comma separated list of GPU to use.')

def main(argv):
    del argv
    if FLAGS.gpu:
	print("gpu is %s" % FLAGS.gpu)
        os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpu
    else:
        print('Please assign GPUs.')
        exit()

if __name__ == '__main__':
    app.run(main)

你可能感兴趣的:(【转】Python之FLAGS用法)