The base64 module is used for base64 encoding and decoding. This encoding method is very common in email. It can encode binary data that cannot be displayed as text information to be displayed. The encoded text size increases by 1/3. Here we mainly introduce the eight methods of base64 (encode, decode, encodestring, decodestring, b64encode, b64decode, urlsafe_b64decode, urlsafe_b64encode ):
1. encode and decode: used to encode and decode files. You can also codec the data in stringio.
2. encodestring and decodestring: used to encode and decode strings.
3. b64encode and b64decode: used to encode and decode strings, and has the function of replacing symbol characters.
Small instance:
# @ Xiaowuyi http://www.cnblogs.com/xiaowuyi # Remove the 1.txt(base6420.content from the C drive and the content is stored in the C drive 2.txt. Import Base64 filea = Open (R ' C: \ 1.txt ' , ' R ' ) Lines = Filea. readlines () writefile = Open (R ' C: \ 2.txt ' , ' W ' ) For I In Lines: Word = I. Strip () B = Base64.decodestring (word) Print B writefile. Write (B) writefile. Write ( ' \ N ' ) Writefile. Close () filea. Close ()
Reprint Please note: @ small Wuyi http://www.cnblogs.com/xiaowuyi