我一直在阅读uuencoding
,并想知道如何使用Python解码此链接中给出的以下示例。
https://en.wikipedia.org/wiki/Uuencoding
原文:Cat
Uuencoded text:#0V%T
Python 2
$ python -c 'print "Cat".encode("uu")'
begin 666 <data>
#0V%T
end
$
Python 3
$ python3 -c "from codecs import encode;print(encode(b'Cat', 'uu'))"
b'begin 666 <data>\n#0V%T\n \nend\n'
$
答案 0 :(得分:0)
它只是原始函数的反函数。...
让我尝试向您展示。我将使用2种常见的编码类型uu和base-64。
Python 3
>>> from pywsd.utils import lemmatize_sentence
Warming up PyWSD (takes ~10 secs)... took 9.307677984237671 secs.
>>> text = "Mary leaves the room"
>>> lemmatize_sentence(text)
['mary', 'leave', 'the', 'room']
>>> text = 'Dew drops fall from the leaves'
>>> lemmatize_sentence(text)
['dew', 'drop', 'fall', 'from', 'the', 'leaf']
这应该输出
from codecs import decode,encode
import uu
orig="Cat"
encoding_types=['uu','base-64']
for et in encoding_types:
enc_data=encode(orig.encode(),et)
un_enc_data=decode(enc_data,et)
print("\n\nEncoding : {}".format(et))
print("Orig : {}".format(orig))
print("Encoded : {}".format(enc_data))
print("byte UnEncoded: {}".format(un_enc_data))
print("utf8 UnEncoded: {}".format(un_enc_data.decode()))
我们需要最终的.decode(),因为我们最初使用strt()将str数据对象转换为字节。