我试图读入文本文件并将输入转换为列表:
model = open('Grids/Dusty_AGN/Z'+Z+'_n'+n+'_alp-'+alpha+'_fluxes.txt','r')
Hafluxfile = model.readline() + model.readline() + model.readline() ; the first three lines of the file contain the values that I need
Haflux = []
Haflux.append([float(x) for x in Hafluxfile.split(' ')])
如果我print Hafluxfile
,我看到的是:
{I>并尝试将此消息追加到cd2>时:
ValueError: could not convert string to float
不,除了冒号之外,没有什么是我没有包括的,它似乎在告诉我,空白阻止了它到达第一个数字?我不知道怎么解决这个问题。在
首先,应该使用} 函数。既然这么说,我将使用^{} 模块。在
+
连接路径组件,而应该使用^{问题是你得到了一些空元素。在
这会照顾他们的。在
项目之间有多个空格。调用^{} 时不要指定分隔符:
而且,看起来你还有前导空格和尾随空格,你可以用^{} 来修剪:
相关问题 更多 >
编程相关推荐