سؤال

I'm working on reading and writing information in HecDSS. I had this script working fine last night except when I opened it this morning I began getting this error:

    ScriptEngine.execute:Error in script Traceback (innermost last):
      File "<string>", line 13, in ?
    NameError: java

The basic code I'm using now is:

    from hec.script import *
    from hec.hecmath import *
    from java import *


    try:  
      dssFile = DSS.open("C:/Documents and Settings/SWP/Desktop/MVCA.dss")
      outflow = dssFile.read("/MAITLAND VALLEY/BLYTH/PRECIP-INC/01DEC2011/30MIN/OBS/")
      newOutflow = outflow.add(10.)

      path = DSSPathname(newOutflow.getPath())
      fPart = path.fPart() + " Test"
      path.setFPart(fPart)
      newOutflow.setPathname(path.getPathname())

      dssFile.write(newOutflow)

    except java.lang.Exception, e :
       MessageBox.showError(e.getMessage(), "Error reading data")

I'm just trying to figure out why it doesn't work all of a sudden. Thanks for any help!

هل كانت مفيدة؟

المحلول

The * import imports all names from the module into the local namespace. So you you do:

from java import *

And the java modules has a submodule called lang, you can access it as lang, not java.lang.

I don't know enough about Jython, but I think that you want something like this:

import java.lang

In which case you can refer to the exception as java.lang.Exception.

Regarding to why it worked before, it probably never raised an exception before. Now it did and it tries to catch it, but it can't find the exception type.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top