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

  • SEARCH
  • Home
  • 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 8908791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:16:23+00:00 2026-06-15T03:16:23+00:00

I’m developping a PyQT application. This application is able to load some data from

  • 0

I’m developping a PyQT application. This application is able to load some data from a database, and then do various analysis on these data. All of this works. But as the analyses can be quite complicated, and as a will not be the only user, I had to develop a system with users defined script.
Basically, there’s a text editor where the user can program his own small python script (with functions). Then the user can save the script or execute it, by loading the file as a module (within the application).

Here, there a simplified version of my application.

The core of the application is in My_apps.py
and the plugins are here in the same folder i.e. Plugin_A.py

this is the code of My_apps.py:

import sys,os

class Analysis(object):
    def __init__(self):
        print "I'm the core of the application, I do some analysis etc..."

    def Analyze_Stuff(self):
        self.Amplitudes_1=[1,2,3,1,2,3]
class Plugins(object):

    def __init__(self):
        newpath = "C:\Users\Antoine.Valera.NEUROSECRETION\Desktop\Model" #where the file is
        sys.path.append(newpath)

        Plugin_List=[]
        for module in os.listdir(newpath):
            if os.path.splitext(module)[1] == ".py":
                module=module.replace(".py","")
                Plugin_List.append(module)   

        for plugin in Plugin_List:
            a=__import__(plugin)
            setattr(self,plugin,a)

    def Execute_a_Plugin(self):
        Plugins.Plugin_A.External_Function(self)


if __name__ == "__main__":

    Analysis=Analysis()
    Plugins=Plugins()
    Plugins.Execute_a_Plugin()

and here is an example of the code of Plugin_A.py

def External_Function(self):
    Analysis.Analyze_Stuff()
    print Analysis.Amplitudes_1   

why do I get :

Traceback (most recent call last):
  File "C:\Users\Antoine.Valera.NEUROSECRETION\Desktop\Model\My_Apps.py", line 46, in <module>
    Plugins.Execute_a_Plugin()
  File "C:\Users\Antoine.Valera.NEUROSECRETION\Desktop\Model\My_Apps.py", line 37, in Execute_a_Plugin
    Plugins.Plugin_A.External_Function(self)
  File "C:\Users\Antoine.Valera.NEUROSECRETION\Desktop\Model\Plugin_A.py", line 8, in External_Function
    Analysis.Analyze_Stuff()
NameError: global name 'Analysis' is not defined

but if I add the 2 lines following lines instead of Plugins.Execute_a_Plugin()

Analysis.Analyze_Stuff()
print Analysis.Amplitudes_1

then, it works.

How could I indicate to every dynamically loaded plugins that he has to use the variables/objects already existing in Analysis? Why can’t I print Analysis.Amplitudes_1 from within the plugin?

Thank you!!

  • 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-15T03:16:24+00:00Added an answer on June 15, 2026 at 3:16 am

    The error message seems perfectly clear: the name “Analysis” doesn’t exist in the namespace of the Plugin_A module you imported, and so External_Function cannot access it.

    When you import the Plugin_A module, it doesn’t get access to the names in the namespace of the importing module, My_apps. So it cannot “see” the instance of the Analysis class that you created there.

    A simple solution to this is to change the signature of External_Function (and other related functions), so that it can take an instance of the Analysis class:

    Plugin_A.py:

    def External_Function(self, analysis):
        analysis.Analyze_Stuff()
        print analysis.Amplitudes_1
    

    My_apps.py:

       ...
    
       def Execute_a_Plugin(self):
           plugins.Plugin_A.External_Function(self, analysis)
    
    if __name__ == "__main__":
    
        analysis = Analysis()
        plugins = Plugins()
        plugins.Execute_a_Plugin()
    

    Note that I have altered the naming so that the instance names don’t shadow the class names.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

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.