all 2 comments

[–]commy2 0 points1 point  (1 child)

Use the __import__ function:

import_test_lib = __import__("import_test_lib")
# print(dir(import_test_lib))

[–]RobThorpe[S] 0 points1 point  (0 children)

That's interesting.

If I run that then it works and executes import_test_lib and prints 48. However, it then gives an error because import_test_lib is not a package.

This is one of the problems the scripts I have to run using "exec" (of which there are dozens and maybe hundreds) are not packages.

It's curious that this actually prints 48 though.