问题描述
我目前正在为 OS X 上的 emesene messenger 编写一个咆哮通知插件.除了显示消息片段外,它几乎可以正常工作.
I am currently writing a growl notification plugin for emesene messenger on OS X. It is nearly working except to when it comes to displaying a message snippet.
消息作为变量传递给growlnotify,但是growl 不接受显示消息中的空格.
The message is passed to growlnotify as a variable, however growl does not accept spaces in the displayed message.
所以我需要帮助的是一个脚本来删除多个单词之间的空格并将其替换为 \ 然后一个空格.
So what i need help with is a script to remove the spaces between multiple words and replace it with a \ then a space.
例如原文:这是一条消息需要什么:这是\一个\消息
e.g.Original: This is a messageWhat is needed: This\ is\ a\ message
我环顾四周,但我不知道如何附加斜杠.
I have looked around at similar answers but i could not work out how to append the slash.
推荐答案
不要尝试使用 os.system()
来做到这一点,而是使用 subprocess
,将程序和参数作为列表传递.
Instead of trying to do this with os.system()
, use subprocess
instead, passing the program and arguments as a list.
这篇关于Python删除空格并追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!