本文整理汇总了Golang中encoding/csv.NewReader函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewReader函数的具体用法?Golang NewReader怎么用?Golang NewReader使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了NewReader函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: main

func main() {
    filecsv := `C:\Users\yejianfeng\Desktop\mxm\skill.csv`
    file, err := os.Open(filecsv)
    if err != nil {
        panic(err)
    }
    defer file.Close()

    reader := csv.NewReader(file)
    roleFolder := `C:\Users\yejianfeng\Desktop\mxm\skill\`
    reader.Read()
    for {
        fields, err := reader.Read()
        if err == io.EOF {
            break
        }

        picurl := fields[15]

        jpg := roleFolder + picurl + ".jpg"
        _, err = os.Open(jpg)
        if err == nil || os.IsExist(err) {
            continue
        }

        png := roleFolder + picurl + ".png"
        _, err = os.Open(png)
        if err == nil || os.IsExist(err) {
            continue
        }

        fmt.Println(fields[0])
    }
}

开发者ID:atree1987,项目名称:MyWorks,代码行数:34,代码来源:checkskill.go

示例2: loadCsvFile

func loadCsvFile(name, urlpath string, timestamp time.Time, force bool) (*csv.Reader, error) {
    filename := filepath.Join(csvDir, name+timestamp.Format(".2006-01-02")+".csv")
    if !force {
        file, err := os.Open(filename)
        if err != nil {
            if !os.IsNotExist(err) {
                return nil, err
            }
        } else {
            return csv.NewReader(file), nil
        }
    }
    log.Info("Downloading %s.csv from Google Spreadsheets", name)
    resp, err := http.Get(csvUrlPrefix + urlpath + csvUrlSuffix)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return nil, err
    }
    err = ioutil.WriteFile(filename, body, 0644)
    if err != nil {
        return nil, err
    }
    return csv.NewReader(bytes.NewBuffer(body)), nil
}

开发者ID:tav,项目名称:wifistat,代码行数:28,代码来源:wifistat.go

示例3: Get

// Get return csv data in array.
func (d *Data) Get() ([][]string, error) {
    if len(d.UnixMapData[d.Date.Unix()]) == 0 {
        data, err := hCache.Get(d.URL(), true)
        if err != nil {
            return nil, fmt.Errorf(errorNetworkFail.Error(), err)
        }
        csvArrayContent := strings.Split(string(data), "\n")
        for i := range csvArrayContent {
            csvArrayContent[i] = strings.TrimSpace(csvArrayContent[i])
        }
        var csvReader *csv.Reader
        if (d.exchange == "tse" && len(csvArrayContent) > 2) || (d.exchange == "otc" && len(csvArrayContent) > 5) {
            if d.exchange == "tse" {
                if d.Name == "" {
                    d.Name = strings.Split(csvArrayContent[0], " ")[2]
                }
                csvReader = csv.NewReader(strings.NewReader(strings.Join(csvArrayContent[2:], "\n")))
            } else if d.exchange == "otc" {
                if d.Name == "" {
                    d.Name = strings.Split(csvArrayContent[2], ":")[1]
                }
                csvReader = csv.NewReader(strings.NewReader(strings.Join(csvArrayContent[5:len(csvArrayContent)-1], "\n")))
            }
            allData, err := csvReader.ReadAll()
            d.RawData = append(allData, d.RawData...)
            d.UnixMapData[d.Date.Unix()] = allData
            d.clearCache()
            return allData, err
        }
        return nil, errorNotEnoughData
    }
    return d.UnixMapData[d.Date.Unix()], nil
}

开发者ID:investislife,项目名称:gogrs,代码行数:34,代码来源:stock_daily_data.go

示例4: parseFlags

func parseFlags() (*csv.Reader, *csv.Reader, error) {
    flag.Parse()
    if *dataFile == "" {
        return nil, nil, fmt.Errorf("probs flag required")
    }

    if *remFile == "" {
        return nil, nil, fmt.Errorf("remaining flag required")
    }

    if *weekNumber < 1 || *weekNumber > 13 {
        return nil, nil, fmt.Errorf("week number must be specified and must be in the range [1,13]")
    }

    csvFile, err := os.Open(*dataFile)
    if err != nil {
        return nil, nil, err
    }
    pReader := csv.NewReader(csvFile)

    csvFile2, err := os.Open(*remFile)
    if err != nil {
        return pReader, nil, err
    }
    rReader := csv.NewReader(csvFile2)

    return pReader, rReader, nil
}

开发者ID:reallyasi9,项目名称:beat-the-streak,代码行数:28,代码来源:bts-mc.go

示例5: Example

func Example() {
    // testFile is a CSV file with CR line endings.
    testFile := bytes.NewBufferString("a,b,c\r1,2,3\r").Bytes()

    // First try reading the csv file the normal way.
    // The CSV reader doesn't recognize the '\r' line ending.
    r1 := csv.NewReader(bytes.NewReader(testFile))
    lines1, err := r1.ReadAll()
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("Without macreader: %#v\n", lines1)

    // Now try reading the csv file using macreader.
    // It should work as expected.
    r2 := csv.NewReader(New(bytes.NewReader(testFile)))
    lines2, err := r2.ReadAll()
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("With macreader: %#v\n", lines2)

    // Output: Without macreader: [][]string{[]string{"a", "b", "c\r1", "2", "3"}}
    // With macreader: [][]string{[]string{"a", "b", "c"}, []string{"1", "2", "3"}}

}

开发者ID:ctessum,项目名称:macreader,代码行数:26,代码来源:reader_test.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng