我有以下陈述,我似乎无法找到问题:
Analysis = 'Trythis'
TestName = 'ThisOne'
NumberIteration = 25
for num in range(NumberIteration):
x= np.loadtxt("%s/results/data_%s/Outputs/$s/%sLCOE.txt" % (Analysis, num , TestName, TestName))
我一直收到以下错误:
np.loadtxt("%s/results/data_%s/Outputs/$s/%sLCOE.txt" % (Analysis, TestName, TestName, TestName))
TypeError: not all arguments converted during string formatting
我尝试使用%d
和%c
代替%s
。使用' _' numpy是否有问题?在使用字符串之前?
答案 0 :(得分:2)
Python抱怨你给%
提供了四个参数,但格式字符串中只有三个%s
。
我认为$s
应该是%s
:
x= np.loadtxt("%s/results/data_%s/Outputs/%s/%sLCOE.txt" % (Analysis, num, TestName, TestName))
# ^^
但请注意,在现代Python代码中,您应该使用str.format
代替:
x= np.loadtxt("{}/results/data_{}/Outputs/{}/{}LCOE.txt".format(Analysis, num, TestName, TestName))