[RESOLVED] ImportError: Cannot import name

Making my first steps in Jython.
This is just a sample setup, not functional intention:

lib/core/personal/myLib.py

def myLog(msg):
    from core.log import logging, LOG_PREFIX
    log = logging.getLogger(LOG_PREFIX + ".this.is.my.log")
    log.info(msg)
    return None

def myLog2(msg):
    from core.log import logging, LOG_PREFIX
    log = logging.getLogger(LOG_PREFIX + ".this.is.my.log2")
    log.info(msg)
    return None

jsr223/personal/test.py

from  personal.myLib import  myLog, myLog2

myLog(str(ir.getItem("ProxySwitchText").state))
myLog2(str(ir.getItem("ProxySwitchText").state))

when saving test.py, I am getting:

2019-05-16 10:59:49.587 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'personal/test.py'
2019-05-16 10:59:49.679 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/personal/test.py': ImportError: cannot import name myLog2 in <script> at line number 1
2019-05-16 10:59:49.681 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: personal/test.py

was lookin an hour for the reason
any idea what I am making here wrong?

I have realized, that though I edit/change lib/core/personal/myLib, the changes are not picked up.
Like having a cache.

You have to reload your modules:

2 Likes
myLog(str(items["ProxySwitchText"])

The items object is a dictionary of all the Items and their current states. Try this in a script…

log.info(dir())

It will display everything available in the context of the script. Everything you see is loaded by default, but there are other OOTB presets available that can be loaded through scriptExtensions. You can also create your own scriptExtensions for sharing objects between scripts and modules. JSR223 Scripting | openHAB

1 Like