2016-10-10 9 views
0

で働いていない私は、ファイルに次のデータを持っている:「lineterminator」キーワード引数がcsv.read

'#export_date\x01video_id\x01name\x01long_description\x01episode_production_number\x02\n' 

これはやって、解析するのに十分な、単純なようだ:

reader = csv.DictReader(f, delimiter=u'\x01', lineterminator=u'\x02\n') 

をしかし、私は、次の操作を行うと、改行が正しく行われる前に項目を解析しません。ここで私が得るものです:

{ 
    '#export_date': u '1475711237318', 
    'video_id': u '382992872' 
    'name': u 'Death Lives', 
    'long_description': u 'When Peter skips out on his anniversary date with Lois in order to play golf with his buddies, he is inexplicably struck by lightning and visited by Death. Instead of escorting Peter to the after-life, Death tells Peter that Lois will leave him in the future unless Peter uses his near-death experience to come to a life-changing revelation. In order to help him, Death takes Peter back to the moment that Peter and Lois met and fell in love.', 
    'episode_production_number\x02': u '2ACX21\x02', 
} 

私はこの問題を解決するだろう、となぜlineterminatorはここで働いていませんどのように?

答えて

2

https://docs.python.org/3/library/csv.html#csv.Dialect.lineterminatorによれば、リーダはlineterminatorキーワード引数を無視:

Dialect.lineterminator 

ライタによって生成されるラインを終了するために使用される文字列。デフォルトは '\ r \ n'です。

注:リーダーは、 '\ r'または '\ n'を行末として認識するようにハードコードされており、リニテレーターは無視されます。この動作は将来変更される可能性があります。

関連する問題