I imported a module as below:
filename = "email"
mymodule = __import__('actions.'+filename)
the problem I have with this is, that the file is immediately executing, and I would much rather execute a specific function from the file (that way I can send variables through it).
for the time being, I am not immediately concerned with whether or not the script executes when I add the line below (when the script is imported) as I will get around it using the if __name__ == "__main__"
trick.
mymodule = __import__('actions.'+filename)
but what I would like to work is when I add the line below, I would like the function to execute. But instead I get an error that the module doesn't have that function even though it exists in the script.
mymodule.OpenEmail(n)
The function name does not really matter, because I have been able to get the script below to work on its own when I run it but when trying to import it in idle and executing the line above I get an error saying that the module does not have that function (or some very similar error). Anyways, the following code is an example script that I am using like a plugin. But my main point is that I am able to dynamically import and execute a script in python but now I would like to be able to send variables through to the file. If I can somehow get functions to work like above I am sure that It would solve my problem.
import webbrowser
def OpenEmail():
handle = webbrowser.get()
handle.open('http://gmail.google.com')
OpenEmail()
print "Your email has been opened"