Python3文档在其codecs page上列出了rot13。
我尝试使用rot13编码对字符串进行编码:
import codecs
s = "hello"
os = codecs.encode( s, "rot13" )
print(os)这会产生一个unknown encoding: rot13错误。有没有不同的方式使用内置的rot13编码?如果Python3中已经删除了这种编码(正如Google搜索结果所显示的那样),为什么它仍然列在Python3文档中?
发布于 2012-05-14 08:44:05
啊哈!我以为它已经从Python3中删除了,但事实并非如此--只是接口发生了变化,因为编解码器必须返回字节(这是str- to -str)。
这是来自http://www.wefearchange.org/2012/01/python-3-porting-fun-redux.html的:
import codecs
s = "hello"
enc = codecs.getencoder( "rot-13" )
os = enc( s )[0]发布于 2013-11-19 15:11:37
在Python 3.2+中,有rot_13 str-to-str codec
import codecs
print(codecs.encode("hello", "rot-13")) # -> uryyb发布于 2021-10-20 20:03:32
rot_13在Python3.0中删除,然后在v3.2中重新添加。rot13是在v3.4中添加的。
在Python 3.4+中,codecs.encode( s, "rot13" )运行得非常好
实际上,现在您可以在rot和13之间使用任何标点符号,包括:
rot-13、rot@13、rot#13等。
https://docs.python.org/3/library/codecs.html#text-transforms
版本3.2中的
新功能:恢复rot_13文本转换。
版本3.4中的更改:恢复rot13别名。
https://stackoverflow.com/questions/10576347
复制相似问题