1

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!

Glynbeard
  • 1,389
  • 2
  • 19
  • 31

1 Answers1

1

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.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
  • Although your reply wasn't exactly the fix I required, it did lead me in the right direction. I forgot to import some libs (from hec.heclib.dss import *) somehow and this fixed everything. – Glynbeard Dec 02 '11 at 14:24
  • 1
    Then I guess it works only accidentally, because some of the imported modules has also imported `java` into its local namespace. The best advice is to stop using `from ... import *`, otherwise you will never know what do you have imported and what not. – Lukáš Lalinský Dec 02 '11 at 14:29