geoffleyland / lua-csv Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I am trying to read a csv file from stdin:
for fields in csv.open(io.stdin) do
for i, v in ipairs(fields) do print(i, v) end
end
I keep getting this error:
lua: /home/lhj/local/share/lua/5.2/csv.lua:340: bad argument #1 to 'open' (string expected, got userdata)
stack traceback:
[C]: in function 'open'
/home/lhj/local/share/lua/5.2/csv.lua:340: in function 'open'
user_comment_size/lua/comment_count.lua:6: in main chunk
[C]: in ?
Would love any feedback?
I downloaded a big pile of reddit comments. Now I am trying to parse the csv file and I am getting an error ":5:91: unmatched quote". I think this is because the comment in the csv file is very large. I have pasted a section of the csv file below:
1430438438,1,t5_2qmg3,t3_34gjek,t1_cqug9su,0,broncos,Broncos,nfl,cqug9su,,0,0,0,tnick771,1,1432703089,"ALRIGHT ALRIGHT ALRIGHT ALRIGHT",,0,0,t3_34gjek
1430438438,2,t5_2qh1i,t3_34gktp,t1_cqug9sv,0,,,AskReddit,cqug9sv,,0,0,0,Toxic_Widow,2,1432703089,"You never forget your first. Her eyes were so beautiful I had to keep them.",,0,0,t3_34gktp
1430438438,3,t5_2qo4s,t3_34g8mx,t1_cqug9sw,0,Bucks2,Bucks,nba,cqug9sw,,0,0,0,yungtito,3,1432703089,"at least we have giannis",,0,0,t3_34g8mx
1430438438,1,t5_2qur2,t3_34cvek,t1_cqug9sx,0,,,excel,cqug9sx,,0,0,0,22Mugatu,1,1432703089,"I got everything to work except that Every Cell in the ranges is a hyperlink, but the hyperlinks don't ""come""with the new cell:
Sub IF_Else_IF_Function()
Dim num As Integer
Selection = Worksheets(""Source"").Range(""B2"")
If Selection = ""1"" Then
Worksheets(""HomePage"").Range(""A10:A18"").Value = Worksheets(""Source"").Range(""F2:F10"").Value
ElseIf Selection = 2 Then
Worksheets(""HomePage"").Range(""A10:A18"").Value = Worksheets(""Source"").Range(""C2:C10"").Value
ElseIf Selection = 3 Then
Worksheets(""HomePage"").Range(""A10:A18"").Value = Worksheets(""Source"").Range(""D2:D10"").Value
ElseIf Selection = 4 Then
Worksheets(""HomePage"").Range(""A10:A18"").Value = Worksheets(""Source"").Range(""E2:E10"").Value
ElseIf Selection = 5 Then
Worksheets(""HomePage"").Range(""A10:A18"").Value = Worksheets(""Source"").Range(""F2:F10"").Value
Else
Cells(10, 10) = ""Fart""
End If
End Sub",,0,0,t1_cqtolo2
1430438438,1,t5_2sf6m,t3_34gj05,t1_cqug9sy,0,,,pathofexile,cqug9sy,,0,0,0,xEldora,1,1432703089,"Apart from all the in-game mechanics, I want to test out the new client, I'm running a horrible crappy toaster and I can manage to run the current PoE at around 20 - 30 FPS. From what I've heard, the new client seems to be really promising and I want to make sure that it can run on crappy toasters too so people like me, don't have problems running PoE and find the best optimization to do so.
Edit : Also, I forgot about removal of desync and the introduction of ping, I'm from India (which means horrible packet loss but I blame that on my ISP from sucking ass) so my ping is always 150 - 200 ms even while using Singapore gateway, this will, to some extent allow me to test out how lockstep mode feels with high ping (which maybe others won't be able to do?) and whether desync is still the more viable option for players with high ping.
",,1430438802,0,t3_34gj05
1430438438,1,t5_2spu5,t3_34g2xu,t1_cqug9sz,0,85,"",HunterXHunter,cqug9sz,,0,0,0,Black_Goreinu,1,1432703089,"I thought it would be fun to add that for a player like Killua, who can run there in a flash and defeat the captain instead of wasting a card, it's the logical choice. I don't even know if t
hey had a leave card, and I think those are expensive.",,0,0,t3_34g2xu
1430438438,8,t5_2qiel,t3_34g9bg,t1_cqug9t0,0,VANStickInRinkNHL,VANStickInRinkNHL,hockey,cqug9t0,,0,0,0,gargamelol,8,1432703089,"gettin stoned, eatin gummy bears, posting to reddit
#myplayoffsmoment",,0,0,t3_34g9bg
1430438438,1,t5_2qo4s,t3_34b832,t1_cqug9t1,0,,,nba,cqug9t1,,0,0,0,GheeGhee,1,1432703089,"Giggle fart!!!",,0,0,t1_cquazx6
1430438438,8,t5_2qstm,t3_34foq8,t1_cqug9t2,0,,,personalfinance,cqug9t2,,0,0,0,ajanitsunami,8,1432703089,"/r/budgetfood mod here. thanks for the plug!",,0,0,t1_cqu6vyn
Hello! I've just started using your tool. As follows:
--split-test.lua
package.path = package.path..";/home/russellh/Git/lua-csv/lua/?.lua"
local csv = require("csv")
local f = csv.open(arg[1],{header=true})
for fields in f:lines() do
for i, v in ipairs(fields) do print(i, v) end
end
--run as lua53 and lua52
lua52 split-test.lua /home/russellh/Git/lua-csv/test-data/header.csv
The above command gives me no results. Can you tell me what I am doing wrong?
Thanks!
local csv = require 'csv'
local inspect = require 'inspect'
local f = csv.open('/tmp/a.csv', {
separator = ';',
header = true,
})
for fields in f:lines() do
print(inspect(fields))
end
/tmp/a.csv
:
a;b;c
1;2;3
Output:
{
a = "1",
b = "2",
c = "3"
}
{
a = ""
}
I'd expect only one iteration. The field is added here. How do I distinguish this extra result from the genuine ones?
How about something like this?
function dump(row, parameters)
local separator = (parameter or {}).separator or ','
local res = {}
for i, value in ipairs(row) do
local value = tostring(value)
if value:find(separator, 1, true) or value:find('"', 1, true) then
res[i] = ('"%s"'):format(value:gsub('"', '""'))
else
res[i] = value
end
end
return table.concat(res, separator)
end
if csv file contains escape quotes, such as
key1, "a\"b\"c"
csv.lua will throw "unmatched quote" exception.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.