-
Notifications
You must be signed in to change notification settings - Fork 2
/
param.py
executable file
·35 lines (29 loc) · 1.09 KB
/
param.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
"""
Prints parameter from parameters file.
Simulation directory name is considered to be
active_particles.naming.sim_directory and parameters file name is considered to
be active_particles.naming.parameters_file.
Script is called according to the following scheme:
$ python param.py [DIRECTORY NAME] [PARAMETER NAME]
"""
import sys
import pickle
from active_particles.naming import sim_directory, parameters_file
from os.path import join as joinpath
try:
with open(joinpath(sim_directory, sys.argv[1], parameters_file),
'rb') as param_file:
param = pickle.load(param_file)
except IndexError: # sys.argv[1] does not exist
print('No directory name found.')
sys.exit()
except FileNotFoundError: # parameters file not found
print('Parameters file %s not found in directory %s.' %
(parameters_file, sys.argv[1]))
sys.exit()
try:
print(param[sys.argv[2]])
except IndexError: # sys.argv[2] does not exist
print('No parameter name found.')
except KeyError: # param[sys.argv[2]] does not exist
print('Parameter %s does not exist.' % sys.argv[2])