Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:48:53+00:00 2026-06-09T10:48:53+00:00

I imported a module as below: filename = email mymodule = __import__(‘actions.’+filename) the problem

  • 0

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"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:48:54+00:00Added an answer on June 9, 2026 at 10:48 am

    Very simply, this is what I did in IDLE

    filename = 'actions.email'
    mod = __import__(filename)
    VAR = getattr(mod, 'email')
    VAR.OpenEmail()
    

    got my email to open!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have imported a c++ native dll method in c#. below is how the
I have the following python code which in my opinion behaves strangely: Imported module:
In Python, once I have imported a module X in an interpreter session using
To describe my questions concisely, please have a look at examples below: Module os
I have a huge haskell file which compiles and runs without any problem. I
I have a module that imports a module, but in some cases the module
I have a class that's being imported in module_x for instantiation, but first I
I'm trying to get the exact module name that a module was imported with,
Lets say I have a python model fibo.py defined as below: #Fibonacci numbers module
When a non built-in module is imported, the interpreter searches in the locations given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.