Reputation: 2786
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, thefrom
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.
Upvotes: 1
Views: 618
Reputation: 814
Is this sufficiently contrived?
os = getattr(__builtins__, "".join(chr(ord(x) - 1) for x in "``jnqpsu``"))("os")
Upvotes: 5