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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:05:06+00:00 2026-05-26T11:05:06+00:00

Short Question Is it possible to call a module as retrieved from the python

  • 0

Short Question
Is it possible to call a module as retrieved from the python dir() function?

Background
I am working on building a custom test runner and would like be able to choose which modules to run based on a string filter. See my examples below for ideal usage.

module_a.py

def not_mykey_dont_do_this():
    print 'I better not do this'

def mykey_do_something():
    print 'Doing something!'

def mykey_do_somethingelse():
    print 'Doing something else!'

module_b.py

import module_a
list_from_a = dir(module_a) # ['not_mykey_dont_do_this', 'mykey_do_something', 'mykey_do_somethingelse']

for mod in list_from_a:
    if(mod.startswith('mykey_'):
        # Run the module
        module_a.mod() # Note that this will *not* work because 'mod' is a string

Output

Doing something!
Doing something else!
  • 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-05-26T11:05:07+00:00Added an answer on May 26, 2026 at 11:05 am
    getattr(module_a, mod)()
    

    getattr is a builtin function that takes and object and a string, and returns the attribute.

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

Sidebar

Related Questions

Short question. I have the following situation: function callbackTest(data, callback) { callback.call(data); } var
Short question: Is it possible to do a redirection, say when a user isn't
The short question, is there an off the self function to make a graph
I have a really short question: Is it possible to communicate/use USB devices on
Question: is it possible to reverse engineer python objects into a string? Info: I'm
Short question : is it possible (on an x64 OS of course) ? If
I think the question title is clear enough: is is possible to stable_sort() a
Short question: Do any of MS's built in Data Objects support INotifyPropertyChanged? Long explination:
Short question - how do you define your view models? Here are some of
Short question: Is the parent of an entity group included in that entity group

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.