Skip to content

Instantly share code, notes, and snippets.

@asmedrano
Created February 24, 2014 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmedrano/9195423 to your computer and use it in GitHub Desktop.
Save asmedrano/9195423 to your computer and use it in GitHub Desktop.
csv write in go.
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