From Python script to Node RED

#1

Hello there,

Is there a way to execute a while python script in my PC and display this informations one by one in Node-RED?

My Python script is:

count = 0
while count < 10:
print(‘Hello’)
count += 1
But what displays in the screen is:

{“topic”:"","_msgid":“6287885c.42fc38”,“payload”:“Hello\nHello\nHello\nHello\nHello\nHello\nHello\nHello\nHello\nHello\n”,“rc”:{“code”:0}}

How can I displays these information in separate payloads without having to run the script over and over?

0 Likes

#2

If that’s your real script why not recreate it in javascript?

If you really want use python how are you executing the python script? are you using the contrib-node or are you using the exec node?

0 Likes

#3

If the only point is to separate the payloads why not to use the standard split node from the pallete?

0 Likes

#4

Thank you for the reply!
I am using exec node.
This script is an exemple for a bigger one, and unfortunately I can’t use a python3 function node.

0 Likes

#5

Thank you for the reply.
I have another python script that has not built-in libraries, my idea is to use Exec Node to run this script and the script will run a while for an undetermined time.

0 Likes

#6

add a delay in the python script and set the exec node output to:
while the command is running - spawn mode

#!/user/bin/python
import time
count = 0
while count < 10:
	print('Hello')
	count += 1
	time.sleep(1)
1 Like

#7

oh my god, thank you for the reply!
The change exec node output solve my problem o/

0 Likes