【发布时间】:2021-07-03 16:00:19
【问题描述】:
我是 python 编程的新手,并试图在编辑字符串文件时了解它是如何工作的。我想调用字符串中的变量或列表或元组并解决值并更新字符串文件。这是一个简单的例子
t_list = ['c','d','e']
doc = '''
domain ()
:types a b c - objects
f"{t_list}" - items
'''
doc_up = doc
我希望我的doc_up 使用列表t_list 的值进行更新。我提到了PEP 498: Formatted string literals,但它不起作用。
我的输出是这样的:
'\n domain ()\n :types a b c - objects\n f"{t_list}" - items\n'
我希望我的输出是这样的:
domain ()
:types a b c - objects
c d e - items
【问题讨论】: