【发布时间】:2011-12-10 12:41:33
【问题描述】:
为时已晚,我一直在尝试编写一个简单的脚本来将点云数据重命名为工作格式。我不知道我做错了什么,因为底部的代码工作正常。为什么for循环中的代码不起作用?它将它添加到列表中,但它只是没有被替换函数格式化。抱歉,我知道这不是调试器,但我真的被困在了这个问题上,其他人可能需要 2 秒才能看到问题。
# 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()
【问题讨论】:
标签: python string formatting replace