Import TensorFlow as TF
#第一个是参数名称, the second parameter is the default value, and the third is the parameter description
tf.app.flags.DEFINE_string (' str_name ', ' def_v_1 ', " Descrip1 ")
Tf.app.flags.DEFINE_integer (' Int_name ', ten," Descript2 ")
Tf.app.flags.DEFINE_boolean (' Bool_ Name ', False, ' DESCRIPT3 ')
FLAGS = Tf.app.flags.FLAGS
#必须带参数, otherwise: ' Typeerror:main () takes no arguments (1 given) ' ; Main parameter name is arbitrarily defined, no requirement
def main (_):
print (flags.str_name) print (
flags.int_name) print
(Flags.bool_ Name
if __name__ = = ' __main__ ': #避免出现import的时候调用main ()
tf.app.run () #执行main函数
You can start the main () function python3 the Test.py–str_name liu–int_name 10来 on the command line.
In Pycharm, you can enter –str_name liu–int_name 10来 input parameters by Run->edit configurations and then in the script parameters.