Python decoding base64 learning notes

Source: Internet
Author: User

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

 

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.