- Reference:
- The difference between Eval/exec/compile: https://stackoverflow.com/questions/2220699/ Whats-the-difference-between-eval-exec-and-compile-in-python
- Use of pickle: https://pythontips.com/2013/08/02/what-is-pickle-in-python/
- Background
- Previously used to print to a file, read out the format by line of Eval. Now it can be realized directly with pickle.
- The difference between pickle_eval_exec:
- Pickle:dump to file, load from file
- Eval:e
val
accepts only a single expression, eval
returns the value of the given expression.
- EXEC:
exec
can take a code block this has Python Statements:loops, try: except:
and class
Function/method def
initions and So on. Return None.
- Use of Pickle: (Pickle.load (), Pickle.dump ())
ImportPicklea= ['Test Value','Test Value 2','Test Value 3']a['Test Value','Test Value 2','Test Value 3']file_name="testfile"#Open the file for writingFileObject = open (file_name,'WB') #This writes the object a to the#file named ' testfile 'pickle.dump (a,fileobject)#Here we close the FileObjectfileobject.close ()#we open the file for readingFileObject = open (file_name,'R') #load the object from the file to Var bb =pickle.load (fileobject) b['Test Value','Test Value 2','Test Value 3']a==btrue
Python Advanced-pickle/eval/exec