首页 > 编程语言 >python 包含有引号和花括号的字符串的格式化

python 包含有引号和花括号的字符串的格式化

时间:2024-10-01 19:49:40浏览次数:8  
标签:uploadtime 格式化 python 引号 update per seconds imei msg

replace 不起作用;
update_per_seconds = "30"
uploadtime_per_seconds = "30"
imei_string = "1234"
### 采用 {0} format 不行 ### 下面replace不行 msg = """{"rmtcmd":"set","dev":{"poll":{"timeout":10,"update":update_per_seconds,"delay":15,"uploadtime":uploadtime_per_seconds,"uploadtype":1,"uploadchange":1,"timestamp":1,"timeoutmode":2,"array":0,"y_trigger":1,"prefix":"","cmdcnt":4}},"imei":"imei_string"}""" msg.replace("update_per_seconds",update_per_seconds) msg.replace("uploadtime_per_seconds", uploadtime_per_seconds) msg.replace("imei_string", imei_string) print(msg)
### 下面可行 s1 = """{"rmtcmd":"set","dev":{"poll":{"timeout":10,"update":""" s2 = ""","delay":15,"uploadtime":""" s3 = ""","uploadtype":1,"uploadchange":1,"timestamp":1,"timeoutmode":2,"array":0,"y_trigger":1,"prefix":"","cmdcnt":4}},"imei":\"""" s4 = """\"}""" msg = s1 + update_per_seconds + s2 + uploadtime_per_seconds + s3 + imei_string+ s4 print(msg)

 

标签:uploadtime,格式化,python,引号,update,per,seconds,imei,msg
From: https://www.cnblogs.com/emanlee/p/18443163

相关文章