python - 将导入复制到变量

标签 python python-3.x

所以,我在学习 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/

相关文章:

python - 在运行 Django 单元测试时,例如在 PyCharm 中,强制删除任何先前的测试数据库(autoclobber)

python - 如何获取内部类列表?

python - 根据条件在数据框 pandas 中创建列

python - iPython locals() 中的 '_oh' 是什么?以及如何在标准 Python IDLE 中让本地人回来或创建新人

python-3.x - Pandas apply 函数 - args 是如何传递的

python - Pygame 将 2 个表面连接在一起

python - numpy.zeros 方法中的这个参数是什么意思?

python - 获取一组中多个分组的 pandas.DataFrame 聚合中每个子组的计数

python-3.x - 未找到驱动程序,即使它列在 pyodbc.dataSources() 中

python-3.x - 传递值的长度为 1,索引意味着 260