I have a Luigi
task with a boolean parameter that is set to True by default:
class MyLuigiTask(luigi.Task):
my_bool_param = luigi.BoolParameter(default=True)
When I run this task from terminal, I sometimes want to pass that parameter as False, but get the following result:
$ MyLuigiTask --my_bool_param False
error: unrecognized arguments: False
Same obviously for false
and 0
...
I understand that I can make the default False and then use the flag --my_bool_param
if I want to make it True, but I much prefer to have the default True.
Is there any way to do this, and still pass False from terminal?
Found the solution in Luigi docs:
class MyLuigiTask(luigi.Task):
my_bool_param = luigi.BoolParameter(
default=True,
parsing=luigi.BoolParameter.EXPLICIT_PARSING)
def run(self):
print(self.my_bool_param)
Here EXPLICIT_PARSING
tell Luigi that adding the flag --my_bool_param false
in the terminal call to MyLuigiTask
, will be parsed as store_false
.
Now we can have:
$ MyLuigiTask --my_bool_param false
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With