lukics
(Slaviša Lukić)
May 16, 2019, 9:06am
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?
lukics
(Slaviša Lukić)
May 16, 2019, 9:35am
2
I have realized, that though I edit/change lib/core/personal/myLib, the changes are not picked up.
Like having a cache.
gitMiguel
(Miika Jukka)
May 16, 2019, 10:17am
3
You have to reload your modules:
[[Home]](README.md)
## Jython Modules
One of the benefits of Jython over the openHAB Xtext scripts is that you can use the full power of Python packages and modules to structure your code into reusable components.
When using the instructions in the [Quick Start Guide](Getting-Started.md#quick-start-guide), these modules should be located in `/automation/lib/python/`
#### Modifying Modules
Changes to a module will not take effect until all other modules and scripts that have imported it have been reloaded.
Restarting OH will remedy this, but another option is to use the reload() function:
```
import myModule
reload(myModule)
import myModule
```
If using imports like `from core.triggers import when`, or if the module is in a package, you will need to use:
```
import sys
This file has been truncated. show original
2 Likes
5iver
(Scott Rushworth)
May 16, 2019, 11:37am
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. JSR223 Scripting | openHAB
1 Like