How can I reload a relative Import?

Asked by Harry Readinger

I have an import library which just has a bunch of common tasks and functions. I could import the whole module, but would prefer to just import the functions that are needed for that particular script. here is some code where I do the import itself:

import sys
importPath = r"C:\Users\hreadinger\Documents\AutomationFW\imports"
if not importPath in sys.path: sys.path.append(importPath)
from masterImport import openTicket , resolveTicket , reset

SO that works fine, no problems.

THe problem comes when, using the Sikuli IDE, I need to reload the import to test a new function i added.

There are currently two workarounds to that problem:
    1) restart the IDE
    2) use a reload(module)

using a relative import, i can't use reload(module), as it errors "NameError: name 'masterImport' is not defined"

Is there a way to reload a relative import?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

only to be sure:

from masterImport import openTicket , resolveTicket , reset
reload("masterimport")
from masterImport import openTicket , resolveTicket , reset

Revision history for this message
Harry Readinger (temporary22) said :
#2

When I use the module name in quotes it throws a "TypeError: reload() argument must be a module" because it reads the argument as a string

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

sorry, stupid answer :-(

I guess you have to use:

import masterimport
reload(masterimport)
from masterimport import openTicket , resolveTicket , reset

Revision history for this message
Harry Readinger (temporary22) said :
#4

That works, thanks @RaiMan

Revision history for this message
Harry Readinger (temporary22) said :
#5

Thanks RaiMan, that solved my question.