Programming/Python

Python 으로 탭/공백으로 구분 된 파일 parsing 하기

쵸코아몬드 2017. 12. 19. 17:18

Python 으로 tab/공백 으로 구분 된 파일 parsing 하여 array로 만들기


#input file open

file = open(file_name, "r")


#output array of table

table_data = []


#for every row

for line in file:

#split by white spaces(column)

tmp_array = line.strip().split(" ")


#remove NO value element

while tmp_array.count(""):

tmp_array.remove("")


table_data.append(tmp_array)