我正在尝试删除空格并从列表中输入,我需要将其作为坐标导入。但是,这似乎不起作用。给出以下错误:
AttributeError: 'list' object has no attribute 'strip'
目前我仍在考虑删除空格(首先必须删除这些空格,然后再输入)。
有没有人有任何建议为什么这不起作用?
代码如下:
# Open a file
Bronbestand = open("D:\\Documents\\SkyDrive\\afstuderen\\99 EEM - Abaqus 6.11.2\\scripting\\testuitlezen4.txt", "r")
headerLine = Bronbestand.readline()
valueList = headerLine.split(",")
#valueList = valueList.replace(" ","")
xValueIndex = valueList.index("x")
yValueIndex = valueList.index("y")
#xValueIndex = xValueIndex.replace(" ","")
#yValueIndex = yValueIndex.replace(" ","")
coordList = []
for line in Bronbestand.readlines():
segmentedLine = line.split(",")
coordList.append([segmentedLine[xValueIndex], segmentedLine[yValueIndex]])
coordList2 = [x.strip(' ') for x in coordList]
print coordList2
其中“Bronbestand”如下:
id,x,y,
1, -1.24344945, 4.84291601
2, -2.40876842, 4.38153362
3, -3.42273545, 3.6448431
4, -4.22163963, 2.67913389
5, -4.7552824, 1.54508495
6, -4.99013376, -0.313952595
7, -4.7552824, -1.54508495
8, -4.22163963, -2.67913389
9, -3.42273545, -3.6448431
提前感谢大家的帮助!