-1
我在用python腳本來替換標籤分隔文本文件的特定列中的某些字符。Python錯誤檢測到不一致的intendation
如果我運行該腳本,我會得到Error:Inconsistent intendation detected。
import csv
# File names: to read in from and read out to
input_file = "test.txt"
output_file = input_file + "-SA_input.txt"
with open(input_file) as to_read:
with open(output_file, "wb") as tmp_file:
reader = csv.reader(to_read, delimiter = "\t")
writer = csv.writer(tmp_file)
desired_column = [1] # text column
for row in reader: # read one row at a time
myColumn = row[desired_column] # build the output row (process)
myColumn.replace('0', ' ')
myColumn.replace('1', ' ')
myColumn.replace('2', ' ')
myColumn.replace('3', ' ')
myColumn.replace('4', ' ')
myColumn.replace('5', ' ')
myColumn.replace('6', ' ')
myColumn.replace('7', ' ')
myColumn.replace('8', ' ')
myColumn.replace('9', ' ')
writer.writerow(row) # write it
幫助非常感謝! :)而不是
with open(input_file) as to_read:
with open(output_file, "wb") as tmp_file: