python - python导入,有多少种方式?

标签 python import

我在阅读有关 python 中的导入的内容时遇到了这个 effbot article关于进口。

Python provides at least three different ways to import modules. You can use the import statement, the from statement, or the builtin __import__ function. (There are more contrived ways to do this too, but that’s outside the scope for this small note.)

我想知道是否有人能够指出一些或所有可以做到这一点的人为方法?我能想到的实现导入的唯一其他方法是

exec("import os") 以及在 exec 语句中创建字符串的所有可能的人为方法。

最佳答案

这是否足够人为设计?

os = getattr(__builtins__, "".join(chr(ord(x) - 1) for x in  "``jnqpsu``"))("os")

关于python - python导入,有多少种方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10444358/

相关文章:

python - 传递并使用 FlaskForm (WTForms) 内的变量

python - 在 python 中,如何将文件复制到目录中并在该目录达到一定大小时停止

java - 编译时包不存在

python - 使用 pandas 创建新列时的条件分割

python - 法语和 lxml 文本

python - 将 Python 长整数转换为 C 字符数组

java - 了解扩展类和导入类之间的区别

linux - 在 ELF 二进制文件中导入名称

csv - SOLR - 从 csv 文件导入 2000 万个文档的最佳方法

java - 当我调用 LocationManger 时无法解析方法 ' requestLocationUpdate'