logo
Loading...

使用newline原因 - Cupoy

1. what will happen if we don't use newline ?2.  w...

pycrawler,pycrawler-d02,newline

使用newline原因

2019/12/11 下午 05:21
Python網路爬蟲討論版
Tommie Chen
觀看數:5
回答數:2
收藏數:0
pycrawler
pycrawler-d02
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:42
    Jeffrey
    贊同數: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.