所以,我在学习 python 时遇到了麻烦,
首先我需要创建一个 python 脚本,它将导入它并将文本复制到名为 text 的变量。
现在,我有:
import this as t
text = t;
这对我不起作用。谁能帮帮我?
更新
我需要得到结果:
print(text);
结果
"The Zen of Python, by Tim Peters"
最佳答案
你可以这样做:
>>> import this
# wall of text follows
>>> import codecs
>>> codecs.decode(this.s, 'rot13')
"The Zen of Python, by Tim Peters\n\nBeautiful is better than ugly.\nExplicit is better than implicit.\nSimple is better than complex.\nComplex is better than complicated.\nFlat is better than nested.\nSparse is better than dense.\nReadability counts.\nSpecial cases aren't special enough to break the rules.\nAlthough practicality beats purity.\nErrors should never pass silently.\nUnless explicitly silenced.\nIn the face of ambiguity, refuse the temptation to guess.\nThere should be one-- and preferably only one --obvious way to do it.\nAlthough that way may not be obvious at first unless you're Dutch.\nNow is better than never.\nAlthough never is often better than *right* now.\nIf the implementation is hard to explain, it's a bad idea.\nIf the implementation is easy to explain, it may be a good idea.\nNamespaces are one honking great idea -- let's do more of those!"
现在您可以执行 text = codecs.decode(见上文)
。
关于python - 将导入复制到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57376293/