Python Advanced-pickle/eval/exec

Source: Internet
Author: User

  • 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.