Created
February 24, 2014 19:37
-
-
Save asmedrano/9195423 to your computer and use it in GitHub Desktop.
csv write in go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
//"fmt" | |
"encoding/csv" | |
"os" | |
) | |
func main(){ | |
file, err := os.OpenFile("mycsv.csv", os.O_CREATE|os.O_WRONLY, 0777) | |
defer file.Close() | |
if err != nil { | |
os.Exit(1) | |
} | |
x := []string{"1", "2", "3"} | |
y := []string{"a", "b", "c"} | |
csvWriter := csv.NewWriter(file) // file here satisfies the Writer Interface | |
csvWriter.Write(x) | |
csvWriter.Write(y) | |
csvWriter.Flush() | |
xy := [][]string{x, y} | |
csvWriter.WriteAll(xy) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment