forked from michabirklbauer/python_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
138 lines (105 loc) · 2.48 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# SCRIPT NAME
# 2024 (c) Micha Johannes Birklbauer
# https://github.com/michabirklbauer/
##### REQUIREMENTS ######
# pip install pandas
#########################
# import packages
import argparse
# import pandas as pd
######## VERSION ########
# version tracking
__version = "1.0.0"
__date = "2024-03-11"
###### PARAMETERS #######
param_1 = 1
param_2 = 2
#########################
docs = """
DESCRIPTION:
A description of the script [multiplies two integers].
USAGE:
main.py [-f1 --factor1]
[-f2 --factor2]
required arguments:
-f1 int, --factor1 int
First factor of multiplication.
optional arguments:
-f2 int, --factor2
Second factor of multiplication.
Default: 2
-h, --help
Show this help message and exit.
--version
Show program's version number and exit.
"""
####### FUNCTIONS #######
# these examples use the numpy docstring style
# https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
def my_product(x: int, y: int) -> int:
"""Returns the product of two integer numbers.
Parameters
----------
x : int
The first factor.
y : int, default = 2
The second factor.
Returns
-------
product : int
The product of x and y.
Examples
--------
>>> from main import my_product
>>> product = my_product(1, 2)
>>> product
2
"""
return x * y
##### MAIN FUNCTION #####
def main(argv=None) -> int:
"""Main function.
Parameters
----------
argv : list, default = None
Arguments passed to argparse.
Returns
-------
product : int
The product of given arguments.
Examples
--------
>>> from main import main
>>> product = main(["-f1", "1", "-f2", "2"])
>>> product
2
>>> product = main(["-f1", "3"])
>>> product
6
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-f1",
"--factor1",
dest="f1",
required=True,
help="First factor of multiplication.",
type=int,
)
parser.add_argument(
"-f2",
"--factor2",
dest="f2",
default=2,
help="Second factor of multiplication.",
type=int,
)
args = parser.parse_args(argv)
p = my_product(args.f1, args.f2)
print(f"The product of {args.f1} * {args.f2} = {p}")
return p
######## SCRIPT #########
if __name__ == "__main__":
m = main()