abseil/abseil-py

Incorret flags.DEFINE_boolean() behavior

AshiakerWang opened this issue · 3 comments

demo python script

from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_boolean('tea',True,'Soggy Leaves')
def test(unused_argv):
   if FLAGS.tea:
        print( "have some tea" )
   else:
        print( "no tea" )
if __name__ == '__main__':
   app.run(test)

The following output is expected while executing python test2.py --tea False in the command line

  • no tea

However, the actual output while executing python test2.py --tea False is

  • have some tea

In other words, no matter which boolean argument(i.e. True or False) is set in the command line, the output of the demo python script remains unchanged.

TIM截图20200527225444
Here is a screenshot of my code running results.

boolean flags do not take an additional argument. --tea means True. --notea means False. --tea=True and --tea=False and related true/false values after = also work.

Thanks for your explanation!