Quopri of the python module: quoted-printable Codec

Source: Internet
Author: User
The quopri and base64 modules are both used for encoding and decoding, and base64 and quoted-printable are both common encodings in emails.
Quoted-printable: The English character is not processed except =. The other characters are encoded as = The hexadecimal number of the two bytes that contain this character. "=/R/N" is available at the end of the row ".

The quopri module only needs to use its encode, decode, encodestring, and decodestring. The first two are encoding and decoding of files (data encoding and decoding in stringio ), the latter two are encoded and decoded strings.

Take a look at the following example: #-*-encoding: gb2312 -*-
Import quopri

A = "only a test data"
B = quopri. encodestring (a) # encode the string
Print B
Print quopri. decodestring (B) # decode the string

Import stringio

C = stringio. stringio ()
D = stringio. stringio ()
E = stringio. stringio ()

C. Write ()
C. Seek (0)

Quopri. encode (c, d, 0) # encode the data in stringio. The third parameter 0 indicates that the space and tab characters are not encoded. The value 1 indicates that the encoding is performed.
Print D. getvalue ()
D. Seek (0)
Quopri. Decode (d, e) # decode the data in stringio
Print E. getvalue ()

F1 = open ("aaa.txt", "W ")
F1.write ()
F1.close ()

F1 = open ("aaa.txt", "R ")
F2 = open ("bbb.txt", "W ")

Quopri. encode (F1, F2, 0) # upload data from aaa.txt to bbb.txt

F1.close ()
F2.close ()

Print open ("bbb.txt", "R"). Read ()

 

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.