Page 1 of 1

Python events: unable to use subroutines !

Posted: Saturday 29 April 2023 20:50
by actyln
Hello,

I've been working hours on a python script outside of domoticz, which now gives me satisfaction.
Now is the time to put it in domoticz, so I copy/paste my script in the embedded Python Events editor.

And I always get the same error: (CRC being one of the subroutines I defined)

Code: Select all

2023-04-29 20:46:01.416 Error: NameError: name 'CRC' is not defined
It seems the Python interpreter used by Domoticz is not able to work with subroutines ... anyone having the same issue ?
I tried to move my script to the scripts/python folder of domoticz and I get the same issue by the way.
On the same machine, if I call from cmdline

Code: Select all

python3 script_time_myscript.py
it works perfectly .... I'm becoming crazy ...

So I did a simple test:

Code: Select all

import DomoticzEvents as DE
DE.Log("tadaaaaa")
This gives me in the domotics logs:

Code: Select all

2023-04-29 20:48:28.344 tadaaaaa
But if I modify it like this:

Code: Select all

import DomoticzEvents as DE
def message(text):
    DE.Log(text)
message("tadaaaaa")
This gives me in the domotics logs:

Code: Select all

2023-04-29 20:49:40.817 Error: Traceback (most recent call last):
2023-04-29 20:49:40.817 Error: File "Script #1", line 6, in <module>
2023-04-29 20:49:40.817 Error: File "Script #1", line 4, in message
2023-04-29 20:49:40.817 Error: NameError: name 'DE' is not defined
It's hard for me to believe that the Python interpreter used by domoticz is not supporting subroutines ....
I couldn't find any topic about this anywhere on this forum or on the net.

Anyone with ideas ?

Thank a lot guys !

Re: Python events: unable to use subroutines !

Posted: Saturday 29 April 2023 23:25
by waltervl
Yes, this have been discussed before: viewtopic.php?p=297430

Re: Python events: unable to use subroutines !

Posted: Thursday 18 May 2023 18:37
by actyln
Hello,

Sorry but this is not the same issue.
My issue is not with import command.
The import works well.

My issue is when using subfunctions with "def".
Then they are not found.