1. reading CSV file doesn't work as expected
- Posted by Norbert Nov 02, 2012
- 1066 views
What is wrong with this code?
include std/pretty.e include std/sequence.e include std/io.e atom fn = open( "eingabe.csv", "r" ) object data = read_lines( fn ) close(fn) sequence mist = split(",",data[1]) puts(1,data[1]) puts(1,"\n") pretty_print(1,mist[2]) -- this line gives an error because data[1] wasn't splitted as expected -- mist[1] still contains the whole inputstring of line no. 1 puts(1,"\n")
I've tried different solutions with the split function in regex.e and an appropriate regular expression but that doesn't work either. In this case, the sequence mist contains another sequence that contains all the single bytes of data[1]. I experimented already a few hours with no useful results. Maybe I have overseen something.
Thanks in advance for helping me!
Norbert
2. Re: reading CSV file doesn't work as expected
- Posted by mattlewis (admin) Nov 02, 2012
- 1046 views
What is wrong with this code?
include std/pretty.e include std/sequence.e include std/io.e atom fn = open( "eingabe.csv", "r" ) object data = read_lines( fn ) close(fn) sequence mist = split(",",data[1]) puts(1,data[1]) puts(1,"\n") pretty_print(1,mist[2]) -- this line gives an error because data[1] wasn't splitted as expected -- mist[1] still contains the whole inputstring of line no. 1 puts(1,"\n")
I've tried different solutions with the split function in regex.e and an appropriate regular expression but that doesn't work either. In this case, the sequence mist contains another sequence that contains all the single bytes of data[1]. I experimented already a few hours with no useful results. Maybe I have overseen something.
Thanks in advance for helping me!
It looks like you're calling the split() function incorrectly. Try:
sequence mist = split( data[1], ',' )
Matt
3. Re: reading CSV file doesn't work as expected
- Posted by Norbert Nov 02, 2012
- 1060 views
Matt, thanks a lot for your fast help!
Now it works as expected.
Regards, Norbert