Last active
August 29, 2015 14:14
-
-
Save rhololkeolke/2961d59974e6bfbb7fd3 to your computer and use it in GitHub Desktop.
Pickle Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy import Symbol, lambdify | |
import pickle | |
def main(): | |
input_symbols = [Symbol('a'), Symbol('b')] | |
my_equation = Symbol('x') = Symbol('a') + Symbol('b') | |
save(input_symbols, my_equation, 'random_file') | |
def save(input_symbols, equation, filename): | |
output_symbols = [str(sym) for sym in input_symbols] | |
output_equation = str(my_equation) | |
output = {'equation': output_equation, 'input_symbols': output_symbols} | |
with open(filename, 'w') as f: | |
pickle.dump(output, f) | |
def load(filename): | |
with open(filename, 'r') as f: | |
output_symbols = output['input_symbols'] | |
output_equation = output['equation'] | |
equation = Symbol(output_equation) | |
input_symbols = [Symbol(sym) for sym in output_symbols] | |
return lambdify(input_symbols, equation) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment