[RESOLVED]Where to put own Jython Modules

rule
jsr223
jython
Tags: #<Tag:0x00007f1e5b50fea8> #<Tag:0x00007f1e5b50fd68> #<Tag:0x00007f1e5b50fc28>
(Slaviša Lukić) #1

Just making my first step in Jython:

Where do I put library modules which can be imported by other modules?

I have created in 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)

test.py

from myLib import  myLog

myLog("Hello World!!!")

I get following error

2019-05-15 19:01:07.297 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'personal/test.py'
2019-05-15 19:01:07.532 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/personal/test.py': ImportError: No module named myLib in <script> at line number 2
2019-05-15 19:01:07.534 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: personal/test.py
0 Likes

(Slaviša Lukić) #2

putting the file in “lib/personal”
image

and refencing:

from  personal.myLib import  myLog

myLog("Hello World")

1 Like

(Scott Rushworth) #3

If you’re more comfortable with using LogAction (what is used in the rules DSL), you can also do this…

from org.eclipse.smarthome.model.script.actions.LogAction import logInfo, logDebug
test = 55555
logInfo("Rules", "This is a test [{}]", test)
logDebug("Rules", "This is a another test [{}]", test)
1 Like

(Slaviša Lukić) #4

Was just a test how to write library modules.
No practical use.

1 Like