python中三重引号的使用

python中三重引号中如何使用占位符

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from string import Template
data = '''{
"name": $para,
"workspace": {
"__type": "Pointer",
"className": "Workspace",
"objectId": "HQQAJJlYXV"
}
}
'''
s = Template(data)
result = s.substitute(para='tim')
print(result)
# 输入
{
"name": tim,
"workspace": {
"__type": "Pointer",
"className": "Workspace",
"objectId": "HQQAJJlYXV"
}
}

参考官网文档:https://docs.python.org/3/library/string.html#string-formatting


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!