-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanalyze.py
More file actions
64 lines (54 loc) · 1.76 KB
/
panalyze.py
File metadata and controls
64 lines (54 loc) · 1.76 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/home/msahil/anaconda3/bin/python
try:
import sys
import getopt
import math
import numpy as np
from termcolor import colored
except:
print('Required libraries not found::')
print('Basic python libraries required:::::')
print(' sys, getopt, math, numpy, termcolor, copy')
exit()
arguments=sys.argv[1:]
try:
args,vals=getopt.getopt(arguments,'q:p:')
except getopt.error as err:
print(str(err))
print(colored(' ERROR','red',attrs=['bold']))
sys.exit(2)
err_out=False
for arg,val in args:
if arg == '-q':
inp=val
elif arg == '-p':
if (val.upper() in ['TRUE','Y','YES']):
err_out=True
elif (val.upper() in ['FALSE','N','NO']):
err_out=False
else:
print('print error requires boolean value')
print(colored(' ERROR','red',attrs=['bold']))
exit()
if ('-q' in arguments):
pass
else:
print('No input expression provided (-q option)')
print(colored(' ERROR','red',attrs=['bold']))
exit()
#-------------------------------------------------------------------------------------------
try:
ans=eval(inp)
except Exception as err:
print('Unidentified functions/arguments detected::')
print(colored(' Use python {math and/or numy} functions','green',attrs=['bold']))
if ('-p' in arguments):
if err_out == True:
print('')
print(colored(str(err),'red',attrs=['bold']))
else:
print(colored(' Use -p to print error','green',attrs=['bold']))
exit()
print(ans)
#-------------------------------------------------------------------------------------------
#===========================================================================================