Tell me how to translate this string into a readable form:

=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?= 

Original line

 ΠΌΠ΅Π½Ρ‚.txt 
  • 2
    This format is called "Quoted-printable", I myself am not a strong python, but this is what Google says according to Quoted-printable python: stackoverflow.com/questions/14249288/… maybe you can use quopri.decodestring - AK ♦
  • @AK I recommend writing an answer. The answer to the link is something in English - tutankhamun
  • @tutankhamun The moderators delete such answers to me: the links to the answer in English cannot be considered as a full answer, and in general this is correct. Since I am not worried about the value of karma, anyone can write the answer. I will not write myself: python is not my main programming language. I suggest the top-starter himself to think and write his answer: he will train the brain and bring a penny of karma. - AK ♦
  • @AK So I did not mean - in the answer to insert the link and that's it. Write in Russian what is written in English by reference. Maybe something else from myself. But this is your business - tutankhamun
  • one
    similar question: Python - email header decoding UTF-8 - jfs

2 answers 2

The email.header module will help you .

 import email.header a = "=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?=" print email.header.decode_header(a) 

The string you quoted is encoded according to RFC2047 . That is, the format of the line is:

 =?ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ°?ΠΏΡ€ΠΈΠ·Π½Π°ΠΊ Ρ‚ΠΈΠΏΠ° кодирования?закодированная строка?= 

The signs of the type of coding are known two Q and B Accordingly, they signify QuotedPrintable and Base64 encoding, respectively.

decode_header() accepts a string in RFC2047 format, recognizes the encoding type, decodes and returns two parameters β€” the decoded string and encoding.

  • 2
    To get the text, you also need to decode() : [(data, encoding)] = decode_header('=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?='); print(data.decode(encoding)) [(data, encoding)] = decode_header('=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?='); print(data.decode(encoding)) - jfs
  • one
    if there is more than one part in a line, for example, a line from rfc 2047: s = '=?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>' , then email.header.make_header() convenient to use: h = make_header(decode_header(s)) . And to get the text = unicode(h) : text = unicode(h) or on Python 3: text = str(h) (you can directly print print(h) ). - jfs
 import quopri a = '=EC=E5=ED=F2=2E' b = quopri.decodestring(a) print(b.decode('windows-1251'))