最近我一直在嘗試使用簡單的腳本來將點雲數據重命名爲工作格式。底部的代碼工作正常,我不知道我做錯了什麼。爲什麼不在for循環中工作?它將它添加到列表中,但它沒有被替換函數格式化。對不起,我知道這不是一個調試器,但我真的被困在這,它可能需要2秒鐘讓其他人看到這個問題。在for循環中運行replace()方法?
# Opening and Loading the text file then sticking its lines into a list []
filename = "/Users/sacredgeometry/Desktop/data.txt"
text = open(filename, 'r')
lines = text.readlines()
linesNew = []
temp = None
# This bloody for loop is the problem
for i in lines:
temp = str(i)
temp.replace(' ', ', ',2)
linesNew.append(temp)
# DEBUGGING THE CODE
print(linesNew[0])
print(linesNew[1])
# Another test to check that the replace works ... It does!
test2 = linesNew[0].replace(' ', ', ',2)
test2 = test2.replace('\t', ', ')
print('Proof of Concept: ' + '\n' + test2)
text.close()
我愛你,我不能相信我沒有看到, :),演員只是其中一件嘗試的事情。這是漫長的一天:)非常感謝你。 – SacredGeometry
@SacredGeometry Np樂於幫助:)。 – chown