-
Notifications
You must be signed in to change notification settings - Fork 27
Alina Layeuskaya #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Alina Layeuskaya #47
Changes from all commits
82115c8
2fdff0b
217f7b4
62112a5
a7e2565
07468f8
588675f
2cb89bd
5974dd1
006e2ff
28f2a57
b86fc50
91c647a
50f4845
7785c6e
260035d
44f7dff
3137044
64347dd
75ded7d
7598b13
d7f5232
d39c1bb
36f1a91
6b3ee62
81ebf2c
85a3384
49884a2
a40e0e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import math | ||
| import operator | ||
| import string | ||
|
|
||
| LETTERS = tuple(string.ascii_lowercase + string.ascii_uppercase) | ||
| DIGITS = tuple(string.digits) | ||
|
|
||
| UNARY_OPERATORS = {'+': (1, operator.add), | ||
| '-': (1, operator.sub), | ||
| } | ||
|
|
||
| BINARY_OPERATORS = {'*': (2, operator.mul), | ||
| '/': (2, operator.truediv), | ||
| '//': (2, operator.floordiv), | ||
| '%': (2, operator.imod), | ||
| '^': (3, operator.ipow), | ||
| '<': (0, operator.lt), | ||
| '<=': (0, operator.le), | ||
| '>': (0, operator.gt), | ||
| '>=': (0, operator.ge), | ||
| '==': (0, operator.eq), | ||
| '!=': (0, operator.ne), | ||
| } | ||
|
|
||
| OPERATORS = UNARY_OPERATORS.copy() | ||
| OPERATORS.update(BINARY_OPERATORS) | ||
|
|
||
| PARENTHESES = ('(', ')') | ||
|
|
||
| OPERATORS_BEGIN = ('+', '-', '*', '/', '%', '^', '<', '>', '=', '!',) | ||
|
|
||
| DOUBLE_OPER_PART1 = ('/', '<', '>', '=', '!',) | ||
| DOUBLE_OPER_PART2 = ('/', '=',) | ||
|
|
||
| BUILT_IN_FUNCTIONS = ('abs', 'round') | ||
| NOT_SUPPORTED_MATH_FUNCTIONS = ('frexp', 'isclose', 'isinf', 'isfinite', 'isnan') | ||
| MATH_CONSTS = ('e', 'pi', 'inf', 'nan', 'tau') | ||
| MATH_FUNCTIONS = tuple([func for func in dir(math) if not func.startswith('_') and | ||
| func not in (MATH_CONSTS + NOT_SUPPORTED_MATH_FUNCTIONS)]) | ||
|
|
||
| ALL_FUNCTIONS = BUILT_IN_FUNCTIONS + MATH_FUNCTIONS | ||
| ALL_FUNCTIONS_AND_CONSTS = ALL_FUNCTIONS + MATH_CONSTS | ||
|
|
||
| ALL_FUNCTIONS_DICT = {el: (4,) for el in ALL_FUNCTIONS} | ||
| ALL_FUNCTIONS_AND_OPERATORS_DICT = ALL_FUNCTIONS_DICT.copy() | ||
| ALL_FUNCTIONS_AND_OPERATORS_DICT.update(OPERATORS) | ||
|
|
||
|
|
||
| DELIMETERS = ('.', ',', ' ') | ||
| ALLOWED_TOKENS = OPERATORS_BEGIN + LETTERS + DIGITS + PARENTHESES + DELIMETERS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import argparse | ||
| from sys import argv | ||
|
|
||
| from pycalc_proc import PyCalcProcessing | ||
|
|
||
|
|
||
| def create_parser(): | ||
| parser_ = argparse.ArgumentParser(prog='Py Calc', | ||
| description='Pure-python command-line calculator', | ||
| epilog='(c) Alina Laevskaya 2019.' | ||
| ) | ||
|
|
||
| parser_.add_argument('EXPRESSION', type=str, help='String formula for processing.') | ||
| return parser_ | ||
|
|
||
|
|
||
| def main(): | ||
| parser = create_parser() | ||
| namespace = parser.parse_args(argv[1:]) | ||
| py_calc_obj = PyCalcProcessing(namespace.EXPRESSION) | ||
| py_calc_obj.launch_processing() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем использовать
sys.argv? ArgumentParser сам знает об аргументах командной строки.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Согласна. args = parser.parse_args()