from absl import appfrom absl import flagsFLAGS = flags.FLAGSflags.DEFINE_string('name', 'Desmond Lua', 'Your name.')def main(argv=None): print('Happy Birthday', FLAGS.name)
Pass flag via cli
if __name__ == '__main__': app.run(main)
python main.py --name Jack
Pass via app.run argv
app.run(main, argv=['main.py', '--name', 'Jack'])
Pass via FLAGS
FLAGS(['main.py', '--name', 'jack'])main()
NOTE: Convert string to argv via
import shlexargv = shlex.split('main.py --name Jack')FLAGS(argv)main()