encoding/csv

3140de70ab04d8f9fc979447b0b4fb16?s=47 pinzolo
April 29, 2017

 encoding/csv

そうだ Go、京都。でのLTスライド

3140de70ab04d8f9fc979447b0b4fb16?s=128

pinzolo

April 29, 2017
Tweet

Transcript

  1. 2.

    $ whoami » NODA Masato » @pinzolo » גࣜձۭࣾ »

    Goྺ1೥ະຬ » goroutine ࢖͍͜ͳ͍ͤͯͳ͍੎ ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)
  2. 5.

    csvutil CSVʹରͯ͋͠Ε͜ΕͰ͖ΔϠπ $ csvutil generate --size 5 --count 10 --header

    ࢯ໊:༣ศ൪߸:ॅॴ:ݐ෺:ϝʔϧ | \ csvutil name --name ࢯ໊ | \ csvutil address --zip-code ༣ศ൪߸ --prefecture ॅॴ --city ॅॴ --town ॅॴ --block-number | \ csvutil building --column ݐ෺ | \ csvutil email --column ϝʔϧ ࢯ໊,༣ศ൪߸,ॅॴ,ݐ෺,ϝʔϧ ౔ా ܚଠ࿠,061-8035,ژ౎෎࿨ޫࢢ੢य़ผӺલ੢ொ42-18,ϓϨεςʔδલՏݪ1926,tempora_doloribus_inventore@twitterbeat.info ݹ઒ ಞਓ,468-2410,௕࡚ݝ౦ࠜࢢޚଂౡଜҰԁ16,ςϥεϥΠϑ1421,charlesstevens@eire.mil ԣా ඣѮ,197-3356,Ѫ஌ݝࢤ໦ࢢਆాࠤٱؒՏ؛44-12-6,ιϨΠϢຑੜ1229,qjordan@roomm.edu Ԯ໺ ٢จ,819-3023,౦ژ౎େࡕࢢฏ໺ُ۠ඌொ44-24-2,άϦʔϯΤεςʔτ1727,tempore_numquam_consequatur@midel.org ৿ࢁ ࠫߐ,289-9318,Ԭࢁݝେࡕࢢ౦ཎ઒۠ࡩ࡞42-6,άϨʔεϰΟϨοδӉ࿨ொ໩ॴ1118,ucooper@voonder.net େ໺ ࠫف,093-0401,৽ׁݝՏ๺܊಺ṗொ໦ڵொ46-10,ύʔϧϨδσϯεསέݪ806,victorpierce@dynabox.edu ࢁ࡚ ྰࡊ,065-9621,ฌݿݝେࡕࢢ࿘଎۠ീ഼ொ39-18,εΠʔτίʔτޫொ506,qui_aut_nihil@meeveo.biz ۚ୔ ༏ೋ,201-6394,ಙౡݝؠख܊࣢ੴொ೔ஔ໺ా36-10,ϓϨεςʔδീ৿Ṥ௕421,ibell@demizz.com দݪ ੣ޗ,877-1329,ੴ઒ݝ٢໺܊໺ഭ઒ଜṗ38-5-10,Ψʔσϯλϫʔ౻Տ಺1120,ab_cum@voomm.info ࡔҪ ྗ໵,967-7366,Ѫඤݝେࡕࢢ੢۠നௗொத௡԰41,ϨΠΫύʔΫ609,perferendis_earum@quamba.edu ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)
  3. 7.

    ओʹ࢖͏΍ͭ csv.Reader io.Reader Λ౉ͯ͠ Read ͔ ReadAll ͢Δ͚ͩɻ csv.Writer io.Writer

    Λ౉ͯ͠ Write -> Flush ͔ WriteAll ͢Δ͚ͩɻ ͲͪΒ΋ io.Reader io.Writer ͱޓ׵ੑ͸ͳ͘ɺ·ͨ interface Ͱ΋͋ Γ·ͤΜɻ ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)
  4. 8.

    αϯϓϧίʔυ src, _ := os.Open("src.csv") defer src.Close() dst, _ :=

    os.Create("dst.csv") defer dst.Close() r := csv.NewReader(src) w := csv.NewWriter(dst) for { record, err := r.Read() if err != nil { if err == io.EOF { break } panic(err) } w.Write(record) } ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)
  5. 10.

    จࣈίʔυ csv.Reader ΋ csv.Writer ΋σϑΥϧτͰ͸จࣈྻΛUTF-8ͱͯ͠ѻ͍ ·͢ɻ ͨͩ͠BOMʹ͸ରԠ͍ͯ͠·ͤΜɻ BOMΛѻ͏ʹ͸Ұ޻෉ඞཁͰ͢ɻ1 ͓͔͛Ͱ CSV

    ͱ͍͑͹ Excel Ͱ͕ܾͯ͢͠૬ੑ͸Α͋͘Γ·ͤΜɻ 1 GoͰBOM෇͖ͷUTF8ͳCSVΛѻ͏ʹ͸ | tail -f pinzo.log ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)
  6. 11.

    ίϝϯτ csv.Reader ʹ͸ Comment ϓϩύςΟ͕͋Γɺ͜ͷ஋͔Β࢝·ΔߦΛί ϝϯτߦͱͯ͠εΩοϓ͠·͢ɻ ͨͩ͠ rune ͳͷͰ //

    Ͱ࢝·ΔߦΛίϝϯτߦͱΈͳ͢Α͏ͳ͜ͱ͸Ͱ ͖·ͤΜɻ ͦ͏ͩ Goɺژ౎ɻ(2017-04-29)