我正在尝试字符串格式-长字符串“替换字段名”。但是我得到了一个“属性错误”。
我已经查过这个错误,但没有类似的答案。
import math
tmpl="This {mod._name_} module defines the value of pie as {mod.pi}"
print(tmpl.format(mod=math))回溯(最近一次调用): 文件“E:/Python/Python/Ch-3/2 2String Long version.py",第14行 打印(tmpl.format(mod=math)) AttributeError:模块“数学”没有属性“名称”
我希望这个错误不会发生。
发布于 2019-06-09 13:21:26
在__name__属性之前和之后需要两个下划线。
tmpl="This {mod.__name__} module defines the value of pie as {mod.pi}"https://stackoverflow.com/questions/56514847
复制相似问题