尝试读取时,CSV文件为空。

huangapple go评论99阅读模式
英文:

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 (
	&quot;fmt&quot;
	&quot;os&quot;
	&quot;encoding/csv&quot;
)




func main() {

	if len(os.Args) &lt; 2 {
		fmt.Printf(&quot;Error: Source file name is required\n&quot;)
		fmt.Println(&quot;Usage:&quot;, os.Args[0], &quot;&lt;filename&gt; \n&quot;)
		return
	}

	file, err := os.Open(os.Args[1])
	if err != nil {
		fmt.Println(&quot;Error:&quot;, 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 = &#39;|&#39;
	reader.Comment = &#39;#&#39;        //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(&quot;Elements: %v&quot;, len(result[i]))
		fmt.Println()
		// Elements.
		fmt.Println(result[i])
	}

}

And the csv is like this :

&lt;iframe src=&quot;http://www.testdata.com/embed/ph5721952ef0c4e&quot; frameborder=&quot;0&quot; height=&quot;481&quot; width=&quot;608&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;|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&#39;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
&lt;iframe src=&quot;http://www.testdata.com/embed/ph5721952ef0c4e&quot; frameborder=&quot;0&quot; height=&quot;481&quot; width=&quot;608&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;|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&#39;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
&lt;iframe src=&quot;http://www.testdata.com/embed/ph5721952ef0c4e&quot; frameborder=&quot;0&quot; height=&quot;481&quot; width=&quot;608&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;|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&#39;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
&lt;iframe src=&quot;http://www.testdata.com/embed/ph5721952ef0c4e&quot; frameborder=&quot;0&quot; height=&quot;481&quot; width=&quot;608&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;|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&#39;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

huangapple
  • 本文由 发表于 2017年3月9日 03:53:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/42680728.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定