@eiram_mahera,
thanks for the link shared.
But in my case pickle might not be the better option as my script has to communicate to groovy in future. I read that pickle won't support other scripts. I am currently working on psudo code. I used config parser & arg parser to bring this functionality. Storing output of each function to ini file and reading again from it.
import sys
import os
import math
import alert
import ConfigParser
import argparse
from alert import alert_user
configParser = ConfigParser.ConfigParser()
configParser.read('sample_updated.ini')
def function_1(a, b):
c = a + b
# write to ini file
configParser.set('Output', 'function_1', str(c))
print "input_1 of function_1: ", a
print "input_2 of function_1: ", b
print "output of function_1: ", c
return c
def function_2(c, b):
d = c * b
# write to ini file
configParser.set('Output', 'function_2', str(d))
print "input_1 of function_2: ", c
print "input_2 of function_2: ", b
print "output of function_2: ", d
return d
def function_3(d, c):
e = d / c
# write to ini file
configParser.set('Output', 'function_3', str(e))
print "input_1 of function_3: ", d
print "input_2 of function_3: ", c
print "output of function_3: ", e
return e
def function_4(d, e):
f = d - e
# write to ini file
configParser.set('Output', 'function_4', str(f))
print "input_1 of function_4: ", d
print "input_2 of function_4: ", e
print "output of function_4: ", f
return f
if __name__ == '__main__':
# alert as a sound
# continue_release = alert_user("shall we proceed further? Y/N: ")
#
# if continue_release == "Y" or continue_release == "y":
parser = argparse.ArgumentParser()
# selection = []
# create argument parsers
parser.add_argument('-function_2', action='store_true', default=None, dest='function_2', help="execute from function_2")
parser.add_argument('-function_3', action='store_true', default=None, dest='function_3', help="execution starts from function_3")
parser.add_argument('-function_4', action='store_true', default=None, dest='function_4', help="execution starts from function_4")
cmd_arguments = parser.parse_args()
# print selected functions
if cmd_arguments.function_2:
function_2(configParser.getint('Output', 'function_1'), configParser.getint('Input', 'value_of_b'))
function_3(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_1'))
function_4(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_3'))
if cmd_arguments.function_3:
function_3(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_1'))
function_4(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_3'))
if cmd_arguments.function_4:
function_4(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_3'))
if not len(sys.argv) > 1:
# store function outputs
function_1(configParser.getint('Input', 'value_of_a'), configParser.getint('Input', 'value_of_b'))
function_2(configParser.getint('Output', 'function_1'), configParser.getint('Input', 'value_of_b'))
function_3(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_1'))
function_4(configParser.getint('Output', 'function_2'), configParser.getint('Output', 'function_3'))
with open('sample_updated.ini', 'w') as configfile:
configParser.write(configfile)