Defaults can be set to None, too.
from typing import Optional
import attr
from clime import clime
@attr.s(auto_attribs=True)
class Dude:
name: Optional[
str
] = None # defaults can be set to None. Make sure to annotate as Optional
def state_name(self):
if self.name:
print(f"hi! my name is {self.name}")
else:
print(f"hi! my name is a secret")
def main():
clime(Dude).state_name()
if __name__ == "__main__":
main()
$ python tutorial_003.py --help
usage: tutorial_003.py [-h] [--name NAME]
optional arguments:
-h, --help show this help message and exit
--name NAME (default: None)
Super!
Name is now a positional argument with a defaul value. The default value is added to the --help.
Try it!
$ python tutorial_003.py
hi! my name is a secret
$ python tutorial_003.py --name mike
hi! my name is mike
That's it. Go ahead. Default to None!