I've been searching and searching, but can't find a way to have a \n in a string converted (parsed?) while just manipulating it.
Here's what I'm trying to do: I receive a message (via MQTT if that matters) that's just a string. For example it might be "Doorbell\nPressed"
.
(I have control over this string, so it can be anything, but only one line. I can't insert an actual newline character in the string though, it's a limitation of the interface to input the string)
I am passing this string to another program, and want the new program to receive:
Doorbell
Pressed
Not the:
"Doorbell\nPressed"
I can't seem to figure out how to do this? If it helps, here's the code:
def on_message(client, userdata, msg): # The callback for when a PUBLISH message is received from the server.
print("Message received-> " + msg.topic + " " + str(msg.payload)) # Print a received msg
subprocess.Popen(["/usr/local/bin/signal-cli", "-u","+12125551212", "send", "-m", str(msg.payload), "+12125551213"])
where msg.payload
is the actual string "Doorbell\nPressed"
.
Interestingly the print of the message prints "Doorbell\nPressed"
instead of the expected:
Doorbell
Pressed
The print output looks like this:
Message received-> queue/signal_message Doorbell\nPressed
What am I missing?