0
안녕하세요 저는 초보자이며 한 번에 한 줄씩 CSV를 반복하려고합니다. CSV에서 읽은 각 행을 해시 테이블에 저장하고 싶습니다. ParseCSVLine는 http://lua-users.org/wiki/LuaCsv에서입니다해시로 csv 읽기
local fp = assert(io.open ("fields.csv")) local line=fp:read() local headers=ParseCSVLine(line,",") -- for i,v in ipairs(headers) do print(i,v) end -- this print outs the CSV header nicely -- now read the next line from the file and store in a hash local line=fp:read() local cols=ParseCSVLine(line,",") local myfields={} for i,v in ipairs(headers) do -- print(v,cols[i]) -- this print out the contents nicely myfields[v]=cols[i] ------ this is where things go bad ----- end for i,v in ipairs(myfields) do print(i,v) end ------ this print nothing!
- : 실험 코드의 현재 상태는 다음과 같다. 그러나 문제는 myfields [v]에게 할당하는 것입니다. 다양한 문서를 보면 [] 안에 허용되는 문법이 다소 이상하며 Lua는 여기에 기호를 사용할 수 없다는 것을 알 수 있습니다. myfields에서 새 테이블을 만드는 방법은 무엇입니까?
나는 내가 가지고 있다는 것을 몰랐다. 이 질문은 분명히 내가 좋아하는 질문이 아니기 때문에 나는 질문 아래에 '별'을 벗겼다는 것을 기억하는 것 같다. 그 당시 당신의 대답은 매우 도움이되었습니다. 감사. – ferg