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 7785685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:17:44+00:00 2026-06-01T20:17:44+00:00

import v_framework as framework framework.loadModules([Maintenance]) framework.Maintenance.showPage() In framework I have: def loadModules(aModules): d_utility =

  • 0
import v_framework as framework
framework.loadModules(["Maintenance"])
framework.Maintenance.showPage()

In framework I have:

def loadModules(aModules):
    d_utility = {"Maintenance":"COOl_M_PAGE"}
    for module in a_aModules:
        exec("import " + d_utility[module] + " as " + module)

When loadModules is executed, it imports the modules in the v_framework namespace. Since I am importing v_framework as framework, I think I should be able to use the imported module using framework.Maintenance. But it does not work that way.
Is there a way to do way to do what I’m trying to do? Alternatively, is there any way to import modules in a namespace other than the one where exec is executed?

  • 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-01T20:17:45+00:00Added an answer on June 1, 2026 at 8:17 pm

    There are libraries for importing modules dynamically. You could use importlib (and another one that might be useful is pkgutil). Now, for your case, I guess this would do the job:

    import importlib
    mods = {}
    def loadModules(aModule):
        global mods
        mods[module] = importlib.import_module(d_utility[module])
        # or maybe globals()[module] = ... would work also (exactly as you expect it to
    

    UPDATE: exec modifies the function’s local namespace, not the global one (I think).

    Hope it helps. 🙂

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

Sidebar

Related Questions

I'm trying to import the tkinter module into my script. I have it installed
import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when
import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel):
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
So I have a one liner: import decimal; h = decimal.Decimal('100.0'); (h > .01,
I have the following code: import matplotlib.pyplot as plt cdict = { 'red' :
i have this code package com.tct.soundTouch; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent;
I have captured a screenshot of my current location from a mapview and import
I'm trying to import a cvs module into an existing git repo. I can
The following code {-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} module Function where import qualified Data.Vector.Unboxed

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.