开发者社区> 问答> 正文

在python的三引号内替换字符串中的字符

我有以下代码:

Integration_Minute = 00
Integration_Schedule = '''{"cluster":{"scheduling":{"shutdownHours":{"isEnabled":true,"timeWindows":["Sat:00:00-Mon:04:xx","Tue:00:00-Tue:04:xx","Wed:00:00-Wed:04:xx","Thu:00:00-Thu:04:xx","Fri:00:00-Fri:04:xx"]}}}}'''
print(Integration_Schedule.replace("xx", Integration_Minute)) 

我想用00来代替xx,但是不行。在python中最好的方法是什么? 我得到的错误是:

  File "s.py", line 4, in <module>
    print(Integration_Schedule.replace("xx", Integration_Minute))
TypeError: expected a character buffer object

问题来源StackOverflow 地址:/questions/59385220/replace-a-char-in-string-within-triple-ticks-in-python

展开
收起
kun坤 2019-12-26 10:47:32 1106 0
1 条回答
写回答
取消 提交回答
  • Integration_Minute = '00'
    >>> print(Integration_Schedule.replace("xx", Integration_Minute))
    
    {"cluster":{"scheduling":{"shutdownHours":{"isEnabled":true,"timeWindows":["Sat:
    00:00-Mon:04:00","Tue:00:00-Tue:04:00","Wed:00:00-Wed:04:00","Thu:00:00-Thu:04:0
    0","Fri:00:00-Fri:04:00"]}}}}
    
    2019-12-26 10:47:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载