跳到主要內容


檔案格式-csv

檔案格式
csv

在rfc4180有詳細的定義跟說明,如果想要了解其定義可以去該網站閱讀,傳送門,如果有天有空或許會翻譯翻譯吧,不過下面講下幾本的定義,以及可能會遇到形式變種。
最標準的定義如下
aaa,bbb,ccc crlf
ddd,eee,ffff crlf
ggg,hhh,iii crlf
觀察上面的格式,會發現重複的字母中間會有用逗號隔開,這是csv檔案很標準的做法,以這樣的方式來隔開資料內容,而crlf是什麼呢?其實就是所謂的\r\n,\r是回車,就是enter,然後常會搭配\n一起使用,這似乎跟打字機的構造有關,換句話說 cr等於\r、lf等於\n,而兩個通常會一起出現所以就會變成crlf,而在windows系統上,必定是crlf一起出現,而linux上,通常都用lf而已,所以csv檔間單定義就是用逗號分開資料且用crlf分行的檔案,之後crlf就一定寫成\r\n,lf就一定寫成\n。
但是在實際狀況上,可能會看到不標準的格式,如只有\n的格式或是資料是用\t(tab鍵)、空白鍵分開的,這也是很常見的形式,另外如果換行的時候有所錯誤,也是需要修正的。
不過大多的csv都是由excel這類型的程式所生成的,只要是這類型的程式生成的,格式基本上就是會固定,但就怕有人用手動生成。
 投影片-slideshare:程式語言概念_變數
 影片-youtube:程式語言蓋面_變數
 程式碼-Github:程式語言概念_變數
下一單元:程式語言概念_常見的檔案格式

留言

這個網誌中的熱門文章

程式語言學習概論(1)

程式語言 介紹

語言學習-English-Lights

Song Lyric Title : Lights Singer :Ellie Goulding Album :  Bright Lights Release Date :  2011 I had a way then losing it all on my own I had a heart then but the queen has been overthrown And I'm not sleeping now the dark is too hard to beat And I'm not keeping up the strength I need to push me You show the lights that stop me turn to stone You shine it when I'm alone And so I tell myself that I'll be strong And dreaming when they're gone 'Cause they're calling, calling, calling me home Calling, calling, calling home You show the lights that stop me turn to stone You shine them when I'm alone Noises, I play within my head Touch my own skin and hope they'll still be there And I think back to when my brother and my sister slept In and on my place the only time I feel safe You show the lights that stop me turn to stone You shine it when I'm alone And so I tell myself that I'...

Python-資料庫-mongodb-pymongo

Python 資料庫 mongodb-pymongo 安裝: linux、mac:pip3 install pymongo windows: import pymongo client = pymongo.MongoClient("mongodb://localhost:27017/") db = client['demo_db'] col = db['demo_col'] dict1 = { "name": "ab123ab456g", "day": "1890-04-05" } result = col.insert_one(dict1)  dict2 = [   { "name": "ki", "day": "1666-1-1"},   { "name": "aa", "day": "1222-11-11"},   { "name": "gg-gg", "day": "1333-02-22"},   { "name": "T-T", "day": "1444-03-02"},   { "name": "f-f", "day": "1555-01-01"} ] result = col.insert_many(dict2) result = col.find_one() print(result) results = col.find() for result in col.find(): print(result) results = col.find() query = {'...