简体   繁体   中英

Importing in python, how many ways can it be done?

I was reading about imports in python and came across this effbot article about imports.

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.)

I am wondering if anyone is able to point out some or all of the contrived ways that this can be done? The only other way to achieve an import that I can think of is

exec("import os") and all the possible contrived methods of creating the string inside the exec statement.

这足够人为吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM