Skip to content

Load module in function and make it globally available

19. June 2014

I had the task to load a Pyhton-module within the ‘main’ function, but it must be globally available!

I found some solutions but they did not work…

…but finally, I found the correct solution:

exec("import my_module") in globals()

This implementation works great, solves my problem very good and I have not found any critical annotations!

Advertisements

From → Python, tutorial

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: