pyufunc.with_argparse#

pyufunc.with_argparse(func_or_class)#

Decorator to add argparse support to a function or class.

Example

>>> # in script.py
>>> from pyufunc import with_argparse
>>>
>>> @with_argparse
>>> def example_function(name: str, age: int = 30):
>>>     print(f'Name: {name}, Age: {age}')
>>>     return None
>>> # in terminal
>>> python script.py --name "John" --age 25
>>> # in script_1.py
>>> from pyufunc import with_argparse
>>> @with_argparse
>>> def example_function(name: str, age: int = 30):
>>>     print(f'Name: {name}, Age: {age}')
>>>     return None
>>> # for class with main method (the main method is required for the class to work with with_argparse)
>>> @with_argparse
>>> class NewClass:
>>>     def __init__(self, name: str):
>>>         self.name = name
>>>     def main(self, age: int = 30):
>>>         print(f'Name: {self.name}, Age: {age}')
>>>         return None
>>> # in terminal
>>> $ python script_1.py NewClass --name "John" --age 25