英文:
Csv empty when trying to read it
问题
这是我的代码:
package main
import (
"fmt"
"os"
"encoding/csv"
)
func main() {
if len(os.Args) < 2 {
fmt.Printf("错误:需要指定源文件名\n")
fmt.Println("用法:", os.Args[0], "<文件名> \n")
return
}
file, err := os.Open(os.Args[1])
if err != nil {
fmt.Println("错误:", err)
return
}
// 在当前方法结束时调用Close()方法
defer file.Close()
// 创建一个新的csvReader用于读取文件
reader := csv.NewReader(file)
// 配置读取器选项 参考 http://golang.org/src/pkg/encoding/csv/reader.go?s=#L81
reader.Comma = '|'
reader.Comment = '#' // 注释字符
reader.FieldsPerRecord = -1 // 每条记录的字段数。设置为负值表示可变
reader.TrimLeadingSpace = true
record, err := reader.Read()
fmt.Println(record)
result, _ := reader.ReadAll()
fmt.Println(result)
for i := range result {
// 元素数量
fmt.Printf("元素数:%v", len(result[i]))
fmt.Println()
// 元素
fmt.Println(result[i])
}
}
而且csv文件是这样的:
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
但输出结果是这样的:
[]
[]
我不明白为什么会出现[]
,如果有人知道为什么文件读取结果为空,请告诉我。
谢谢和问候。
英文:
Here is my code :
package main
import (
"fmt"
"os"
"encoding/csv"
)
func main() {
if len(os.Args) < 2 {
fmt.Printf("Error: Source file name is required\n")
fmt.Println("Usage:", os.Args[0], "<filename> \n")
return
}
file, err := os.Open(os.Args[1])
if err != nil {
fmt.Println("Error:", err)
return
}
// deferred call to Close() at the end of current method
defer file.Close()
//get a new cvsReader for reading file
reader := csv.NewReader(file)
//Configure reader options Ref http://golang.org/src/pkg/encoding/csv/reader.go?s=#L81
reader.Comma = '|'
reader.Comment = '#' //Comment character
reader.FieldsPerRecord = -1 //Number of records per record. Set to Negative value for variable
reader.TrimLeadingSpace = true
record, err := reader.Read()
fmt.Println(record)
result, _ := reader.ReadAll()
fmt.Println(result)
for i := range result {
// Element count.
fmt.Printf("Elements: %v", len(result[i]))
fmt.Println()
// Elements.
fmt.Println(result[i])
}
}
And the csv is like this :
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
<iframe src="http://www.testdata.com/embed/ph5721952ef0c4e" frameborder="0" height="481" width="608" scrolling="no"></iframe>|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg|http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)1.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)2.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)3.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)4.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)5.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)6.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)7.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)8.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)9.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)10.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)11.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)12.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)13.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)14.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)15.jpg;http://i0.cdn2b.image.testdata.zhncdn.com/videos/201604/28/75158391/original/(m=eaf88daaaa)16.jpg| it's done|allhomedata;hardware;wf;couple;ITwjob;dsshot;small-tera;forceager;wf;tamed-cat;bg-wf-chicken;cowanimal;tracy-rod;tamed;ds-on-table|wf;dsshots;Hardware;force||976|51703|122|40
but the output is like :
[]
[]
i don't understand why the [] appear ....
If anyone have any idea why the file reading appears to be empty.
Seems that the reading process seems to be broken.
thanks and regards
答案1
得分: 1
你的主要问题是你没有检查错误,至少在你的示例中没有。如果你检查从reader.Read()返回的错误,你会知道它是ErrBareQuote,为了避免这个错误,你需要将csv.Reader的LazyQuotes字段设置为true。这里是你代码的一个可工作版本:https://play.golang.org/p/3y-T1DCsp6
英文:
Your main problem is you're not checking errors, at least in the example you're not. If you check the error returned from reader.Read() you would know that it is ErrBareQuote, to avoid that error you have to set the csv.Reader's LazyQuotes field to true. Here's a working version of your code https://play.golang.org/p/3y-T1DCsp6
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论