Summary of Basic Knowledge of Python Operation

python operation Introduction:

1.1. Data object persistence
2.At some point, the content of the data object needs to be saved so that it can be read the next time the program starts. This requires the object to be persisted. Please see the following example
4. import pickle
7.before_d = {}
8.before_d[1]= "Name 1"
9.before_d[2]= "Name 2"
10.before_d[3]= "Name 3"
13. fout = open("dict1.dat", "w")
14. pickle.dump(before_d, fout, protocol=0)
15. fout.close()
18. fin = open("dict1.dat", "r")
19. after_d = pickle.load(fin)
20.fin.close()
22.print ( before_d ) # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}
23.print ( after_d ) # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}
24.It can be seen that we save the content of the data object as a file, which can be used for some simple cache processing, especially when writing some relatively small programs, which is very useful
26.Regular expression replacement
27.Goal: Replace overview.gif in the string line with another string