|
1 | 1 | import math |
2 | 2 | from os import system |
| 3 | +import readline |
3 | 4 |
|
4 | 5 | # import all components |
5 | 6 | from src.MathFramework import MathFramework |
6 | | -from src.mathframework.Parabola import Parabola |
7 | | -from src.mathframework.quadratic_equation import quadratic_equation |
8 | | -from src.mathframework.progression import progression |
| 7 | +# from src.mathframework.Parabola import Parabola |
| 8 | +# from src.mathframework.quadratic_equation import quadratic_equation |
| 9 | +# from src.mathframework.progression import progression |
9 | 10 |
|
| 11 | +from os import listdir |
| 12 | +from os.path import isfile, join |
| 13 | + |
| 14 | +files = [f.replace('.py', '') for f in listdir('src/mathframework') if isfile(join('src/mathframework', f))] |
| 15 | +for _import in files: |
| 16 | + im = __import__('src.mathframework.'+_import, globals(), locals(), ['*'], 0) # get imported module and import all |
| 17 | + func = getattr(im, _import) # find executable class |
| 18 | + globals()[_import] = func # save it |
10 | 19 |
|
11 | 20 | def do(_input: str, MF_SCRIPT_ITEMS: list = ['var', 'use', 'run', 'sh']): |
12 | 21 | _topics = _input.split() |
13 | 22 | if _topics[0] in MF_SCRIPT_ITEMS: |
14 | | - if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3]) |
15 | | - if (_topics[0] == 'sh'): system(_topics[1]) |
16 | | - elif (_topics[0] == 'run'): locals()[_topics[1]]() |
17 | | - else: |
| 23 | + if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3]) # create var |
| 24 | + if (_topics[0] == 'sh'): system(_topics[1]) # use bash(system shell) |
| 25 | + elif (_topics[0] == 'run'): locals()[_topics[1]]() # run function |
| 26 | + else: # call eval() |
18 | 27 | _result = eval(_input) |
19 | 28 | print(f'{_input.replace("*", "×").replace("/", "÷").replace("-", "−")} is {_result}') |
20 | 29 |
|
|
0 commit comments