Skip navigation

Python’s imp module is a bit of a bear, but thanks to the groundwork in this thread, I got it straitened out. Here’s some lightly tested sample code.


import imp
# the path variable is optional, but possibly necessary
tmp = imp.find_module("module", ["relative/path", "/absolute/path"])
try:
# the names of the two constants do not seem to matter
  module = imp.load_module("name", tmp[0], "path", tmp[2])
finally:
  tmp[0].close()
module.thing

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: