使用newline原因
1. what will happen if we don't use newline ?
2. what's its meaning ?? and what's file object ??
If csvfile is a file object, it should be opened with newline=''.
thx
回答列表
-
2019/12/11 下午 06:42Jeffrey贊同數:1不贊同數:0留言數:0
這個意思是說:我們會把副檔名為csv(for example: xxxx.csv) 視為一個物件,針對這個檔案:開啟,資料處理,轉格式.....等等操作。
要用‘newline’ 主要是因爲csv 寫檔格式的關係。避免每一行的data 串連而把 /r 當作data
-
2019/12/12 上午 11:26張維元 (WeiYuan)贊同數:1不贊同數:0留言數:1
1. what will happen if we don't use newline ?
=> You could get the result when you run it first.
2. what's its meaning ?? and what's file object ??
If newline='' is not specified, newlines embedded inside quoted fields will not be interpreted correctly, and on platforms that use \r\n linendings on write an extra \r will be added. It should always be safe to specify newline='', since the csv module does its own (universal) newline handling.