我想使用Python 3中的.format()方法返回一个特定的数值,并在其中使用div运算符(/)进行小的计算。
但是,消息框库不支持此功能。
#Remind dilutions
if self.initial_concentration > (1000):
messagebox.INFO('Since your dilution is in the lowest range, consider a 1:100 pre-dilution first, so you would have {:2f}').format(answer)
你知道我怎么能克服这个?
谢谢
答案 0 :(得分:2)
messagebox.INFO('Since ... have {:2f}').format(answer)
# ^
# calling `format` method of the return value of the `INFO(..)`,
# (not against the formatting string)
# which may not exists; possibly causing AttributeError
以上行应替换为:
messagebox.INFO('Since ... have {:2f}'.format(answer))
答案 1 :(得分:2)
format
是一个str函数,你应该从str而不是INFO中使用它。
解决方案:
messagebox.INFO('Since your dilution is in the lowest range, consider a 1:100 pre-dilution first, so you would have {:2f}'.format(answer))