iancoleman
iancoleman

Reputation: 2786

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.

Upvotes: 1

Views: 618

Answers (1)

Eric W.
Eric W.

Reputation: 814

Is this sufficiently contrived?

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

Upvotes: 5

Related Questions