-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
24 lines (17 loc) · 700 Bytes
/
example.py
File metadata and controls
24 lines (17 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import glob
# Automatically scan all files ending with _example.py in the examples folder
examples_dir = os.path.join(os.path.dirname(__file__), 'examples')
example_files = glob.glob(os.path.join(examples_dir, '*_example.py'))
# Extract example names from filenames (remove path and suffix)
EXAMPLE = []
for file_path in example_files:
filename = os.path.basename(file_path)
example_name = filename.replace('_example.py', '')
EXAMPLE.append(example_name)
print("Choose an example:")
for i, example in enumerate(EXAMPLE):
print(f"{i+1}.{example}")
choice = int(input("Enter your choice: "))
import_path = f"examples.{EXAMPLE[choice-1]}_example"
__import__(import_path)