Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

jython 2.2.1 undefined variable

Ferry
2011-03-29
2013-03-15
  • Ferry
    Ferry
    2011-03-29

    Hello,
    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)
    dataHandler.enableDebug()
    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):
            self.testRunner()

    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.

    Cheers,

    Fabio