I have a CSV on a S3 and I try to read it line for line with open(). The CSV has new lines (n) within the lines but a single line always ends with carriage return and new line (rn).
When I try to read the file, my lines always get split in the middle instead of the end. Setting the newline parameter seems to make no effect.
Examples I've tried:
open(uri='s3://my-bucket/my-file.csv', newline='\r\n')):
open(uri='s3://my-bucket/my-file.csv', mode='rb', newline='\r', encoding='UTF-8')):
my-file.csv:
column1,column2,column3\r\n
123,abc\n,456\r\n
234,bcd\n,567\r\n
345,cde\n,678\r\n
The lines get split like so:
column1,column2,column3
123,abc\n
456\r\n
...
instead of:
column1,column2,column3
123,abc\n456\r\n
...
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Darwin-18.7.0-x86_64-i386-64bit
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
smart_open 2.1.0
Before you create the issue, please make sure you have:
How does Python's built-in open() behave on your CSV?
You're right @piskvorky. It behaves the same way.
I could fix my issue with the CSV module:
datareader = csv.DictReader(open('s3://my-bucket/my-file.csvv', encoding='utf-8'), delimiter=',')
for order, row in enumerate(datareader):
I will close this issue. Thank you
EDIT: formatting
Most helpful comment
How does Python's built-in
open()behave on your CSV?