我有两个标志f1和f2,f1是一个布尔标志。当f2被设置为True时,我希望将其标记为f1。absl-py有可能做到这一点吗?
发布于 2022-05-05 15:09:11
您可以使用验证器:
from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_bool("f1", False, "some flag")
flags.DEFINE_string("f2", None, "some other flag")
flags.register_validator(
# the flag to validate
"f1",
# a function that takes that flag's value and returns whether it's valid
lambda value: not value or FLAGS.f2 is not None,
# a message to print if it isn't
message="if f1 is set, f2 needs to be set"
)
def main(argv):
pass
if __name__ == '__main__':
app.run(main)https://stackoverflow.com/questions/72129286
复制相似问题