forked from alcantarar/ASB_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_script.py
53 lines (46 loc) · 1.19 KB
/
main_script.py
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
#!/usr/bin/env python
'''
main_script.py
---------------------------------------------------------
This is the ASB tutorial master Python script, the main
entry point for running this tutorial in Python. You will
not need to modify this file.
Usage:
$ python main_script.py
'''
def runFile(num, args):
'''Execute an additional python script
- num {int} the script number
- args {dict} Additional global variables that need
to be defined for this script to run.
'''
fn = 'python_scripts/script_%d.py' % num
f = open(fn)
code = compile(f.read(), fn, 'exec')
exec(code, args)
f.close()
return None
def main():
'''Run the tutorial
This function also gracefully handles when users
do not have required third-party packages.
'''
try:
import pandas as pd
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.axis('off')
for i in range(1,6):
runFile(i, {
'pd': pd,
'plt': plt,
'ax': ax,
'fig': fig})
plt.show()
except ImportError as err:
mod = str(err).split(' ')[-1].replace("'", '')
msg = '\nERROR: %s is not installed. ' % mod
msg += 'Try running:\n\n\t$ conda install %s' % mod
print(msg)
if __name__ == '__main__':
main()