-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_script001.py
More file actions
executable file
·47 lines (41 loc) · 1.24 KB
/
app_script001.py
File metadata and controls
executable file
·47 lines (41 loc) · 1.24 KB
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
#!/usr/bin/env python3
# coding: utf-8
import cyclopts # This 3rd-party package should be included in the environment.yml file pip section.
from pathlib import Path # This Python Standard Library package should not be added to environment.yml.
app = cyclopts.App(
help="Help string for this app.",
config=cyclopts.config.Json(
"app_script001_config.json", # Use this file, if in cwd (or a parent).
search_parents=True,
)
)
@app.default
def main(
name: str = "Bob",
age: int = 33,
outdir: str = "./"
):
"""
This is the default function called when the script
is run from the command line. You can put any lines
of code you might normally have globally in a
simple Python "script" here.
Parameters
----------
name: str
The name of the person.
age: int
The age of the person.
outdir: str
The (created) directory the output file will be put in.
"""
outpath = Path(outdir)
outpath.mkdir(exist_ok=True, parents=True)
outpath /= "main_output.txt"
output = f"{name}'s age is {age}.\n"
print(output)
with outpath.open("w") as filehandle:
filehandle.write(output)
return output
if __name__ == "__main__":
app()