我试图获取fortune命令的输出并将其发送到基于web的WhatsApp。我可以从fortune命令获取输出,但是当我将其发送到WhatsApp时,fortune输出将作为单独的行/消息输出。我怎么把它变成一个信息?谢谢。在fortune_list = ["(?i)art","(?i)comp","(?i)cookie","(?i)drugs","(?i)education","(?i)ethnic","(?i)food"]
for i in range(len(fortune_list)):
if re.search(re.compile(fortune_list[i]),reply):
cmd = ['fortune', fortune_list_reply[i]]
output = subprocess.Popen( cmd, stdout=subprocess.PIPE ).communicate()[0]
print output
input_box[1].send_keys(output)
time.sleep(1)
b.find_element_by_class_name('send-container').click()
终端上的输出(print output)
输出在WhatsApp上作为单独的消息发送。在
作为单个消息的期望输出。在
编辑1:使用repr:将字符串与以下字符合并。使用regex replace替换字符无效。在
"XXXI:\n\tThe optimum committee has no members.\nXXXII:\n\tHiring consultants to conduct studies can be an excellent means of\n\tturning problems into gold -- your problems into their gold.\nXXXIII:\n\tFools rush in where incumbents fear to tread.\nXXXIV:\n\tThe process of competitively selecting contractors to perform work\n\tis based on a system of rewards and penalties, all distributed\n\trandomly.\nXXXV:\n\tThe weaker the data available upon which to base one's conclusion,\n\tthe greater the precision which should be quoted in order to give\n\tthe data authenticity.\n\t\t-- Norman Augustine\n"
编辑2:答案已添加。在