-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain002.py
More file actions
44 lines (30 loc) · 1 KB
/
Copy pathmain002.py
File metadata and controls
44 lines (30 loc) · 1 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
from typing import Any, Callable
type Data = dict[str, Any]
type ExportFn = Callable[[Data], None]
def export_pdf(data: Data) -> None:
print(f"Exporting data to PDF: {data}")
def export_csv(data: Data) -> None:
print(f"Exporting data to CSV: {data}")
def export_excel(data: Data) -> None:
print(f"Exporting data to Excel: {data}")
def export_json(data: Data) -> None:
print(f"Exporting data to JSON: {data}")
export_functions: dict[str, ExportFn] = {
"pdf": export_pdf,
"csv": export_csv,
"excel": export_excel,
"json": export_json,
}
def export_data(data: Data, format: str) -> None:
export = export_functions.get(format)
if export is None:
raise ValueError(f"Invalid format: {format}")
export(data)
def main() -> None:
sample_data: Data = {"name": "John", "age": 30}
export_data(sample_data, "pdf")
export_data(sample_data, "csv")
export_data(sample_data, "excel")
export_data(sample_data, "json")
if __name__ == "__main__":
main()