python字符串合并输出_使用Python将终端输出字符串合并为一个字符串

我试图获取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)

dfe146c620a4d1458c7a813e6416540b.png

输出在WhatsApp上作为单独的消息发送。在

87fffccc4c035d58969a9d7b1f747ccd.png

作为单个消息的期望输出。在

9b38ce113c07df22f9177ede1b51d5db.png

编辑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:答案已添加。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值