I'm confused about the function flags.DEFINE_boolean
when I'm using python's absl module. Below is my code, when I set the parameter default to True
, I can no longer dynamically modify is_student
to False
via the command line.
from absl import app, flags
mmap = flags.FLAGS
flags.DEFINE_boolean(
name='is_student',
default=True,
help='Are you a student?',
)
def func(_): # 'python test.py --is_student False' doesn't work
print(mmap.is_student) # mmap.is_student is always True
if __name__ == '__main__':
app.run(func)
At the same time, I found that when setting the parameter default to False
, as long as the is_student
is mentioned on the command line, the is_student
is triggered as True
. Can I just set the default value of flags.DEFINE_boolean
to False
?
--is_student False
doesn't mean you're setting is_student
to False
. The --is_student
means you're setting is_student
to True
, and the False
is interpreted as an entirely unrelated argument.
To turn off the is_student
flag, use --nois_student
.