[RESOLVED] ImportError: Cannot import name

jsr223
rules
jython
Tags: #<Tag:0x00007f1e650368c8> #<Tag:0x00007f1e65036788> #<Tag:0x00007f1e65036648>
(Slaviša Lukić) #1

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?

0 Likes

(Slaviša Lukić) #2

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

0 Likes

(Miika Jukka) #3

You have to reload your modules:

2 Likes

(Scott Rushworth) #4
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. https://www.openhab.org/docs/configuration/jsr223.html#default-preset-importpreset-not-required

1 Like