Basic python question- script recieves UDP from TD UDP out - then what?

also, how do i properly paste code/pseudocode in my posts with this new fancy forum?:slight_smile:

I need a Python guru to help me understand something:


while True:

data, addr = serverSock.recvfrom(1024)
command = data.decode()
print(data)
print(command)
command

this receives UDP message in external python script, proper and prints, but it doesn’t send ‘command’ into my waiting API script. I cant figure why?
output is:


b’print(robot.homed())\x00’
print(robot.homed())


which is fine and confirms received msg.,
but ‘command’ doesn’t execute anything. Something about data decode makes the received message into a string, but what am i missing to execute that ?

Are you trying to run the code print(robot.homed())?

If so, use exec(command)

P.S. Enclose code with three backticks (is that what you call them?): ```

thks, yes execute was what i was looking for

regarding posting code here:

```python
a = 1
b = 2
debug('hello', a+b)
```

this results in:

a = 1
b = 2
debug('hello', a+b)

cheers
Markus

1 Like