jython 2.2.1 undefined variable

  • Ferry

    Ferry - 2011-03-29

    I have the following jython module which runs fine with jython 2.2.1.
    The modul controls the call of further jython modules.

    from net.grinder.script import Test
    from net.grinder.script.Grinder import grinder
    from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
    from HTTPClient import NVPair
    from sit.grinder import XMLDataHandler
    from at.spardat.gcms.grindertest import GcmsXMADataHandler

    dataHandler = GcmsXMADataHandler.getHandler("all", grinder.statistics)
    scripts = dataHandler.getAllScripts()

    # Ensure modules are initialised in the process thread.
    for script in scripts: exec("import %s" % script)

    def createTestRunner(script):
        exec("x = %s.TestRunner()" % script)
        return x

    class TestRunner:
        def __init__(self):
            #tid = grinder.getThreadNumber()
            nextScript = dataHandler.getNextScript()
            self.testRunner = createTestRunner(nextScript)

        # This method is called for every run.
        def __call__(self):

    The Pydev editor states the following error:

    undefined  variable x (line 17)

    Do anybody have some suggestions what goes wrong?

    :-Q ferry

  • Fabio Zadrozny

    Fabio Zadrozny - 2011-04-09

    PyDev won't analyze/execute code in exec statements, so, it doesn't know that

    exec("x = %s.TestRunner()" % script)

    will end up with a 'x' in the namespace.

    you could change that to be:

    x = eval('%s.TestRunner()' % script) and then it'd at least get 'x' in the namespace.




Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks