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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:49:38+00:00 2026-06-12T15:49:38+00:00

I am attempting to access some functions in file that’s one directory below the

  • 0

I am attempting to access some functions in file that’s one directory below the file where I want to use them. I am looking to do this in a dynamic fashion, as I will not know prior to runtime which functions the user will want to use.

I will ask the user for a particular scenario, for example, and if they request the 1424 scenario, I would like to have access to functions in a ‘scenarios/scenario1424.py’ file.

I am looking to do this using importlib.import_module(…), but I can’t seem to have it let me access those functions even though I seem to be successfully importing the file module.

Directory structure:

code/
  - main.py
  scenarios/
    - __init__.py (empty)
    - scenario1420.py
    - scenario1421.py
    - scenario1424.py

Inside a scenario file, I’ll have a bunch of methods defined like so:

def run():
  .......

def compute():
  .......

I seemed to be able to import the module using importlib.import_module('scenarios.scenario1424') (returns <module 'scenarios.scenario1424' from 'scenarios/scenario1424.pyc'>), but when I attempt to access a function like: scenario1424.run() , I get a NameError (NameError: name 'scenario1424' is not defined).

Any thoughts?

  • 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-12T15:49:39+00:00Added an answer on June 12, 2026 at 3:49 pm

    import_module returns the module object itself, it is your own responsibility to assign it to a name you can use. So in your case it would be

    scenario1424 = importlib.import_module('scenarios.scenario1424')

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

Sidebar

Related Questions

Am interoping a c++ dll and am attempting to access it's functions. Below is
I have access to some images that can be gathered like this: http://www.example.com/imageGetter.php?a=0001 If
We have a scenario where some .NET code is attempting to access the current
I am attempting to do some dynamic loading that includes javascript, css, and html
Currently, we use an unmanaged DLL from a vendor that allows us to access
I'm attempting to use jQuery to access a method in an asmx webservice. When
So i am attempting to learn some jquery to use in a form to
I am attempting to access the HTML of a page after it has been
I am attempting to access values in the Categories and Keywords information for a
I am attempting to access elements with a specific class name from a page

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.