Open stucka opened 8 years ago
Odd, I'm not seeing this issue in either Python 2 or 3. Can I see the source file or a portion thereof?
Should be here: https://gist.github.com/stucka/5e82393945fa7b6cdba7
I'm looking in a text editor, and I've got: data + cr nothing + cr + lf data + cr nothing + cr + lf
OK, I see it happening when I run the script on Windows. Let me look into fixing this.
Looks like it's a thing written circumspectly about in the docs: https://docs.python.org/2/library/csv.html#csv.writer via http://stackoverflow.com/questions/1170214/pythons-csv-writer-produces-wrong-line-terminator
Patched with https://github.com/PalmBeachPost/postgeo/commit/65adc58c6b92fbc5bc79d775e361a4d242679f22 ... and life goes on. =)
Fixed by @amikiri patch in https://github.com/PalmBeachPost/postgeo/commit/c33dcf33b628fa4837264458838e444eb817623a
We're still having problems with this, sadly, such that files created by postgeo.py in Windows aren't readable by cellspacer.py.
I'm thinking the answer might be: Open CSVs with rU Write CSVs with w or possibly wb Don't force csvwriter into any particular behavior
I haven't tested this, however, and my efforts to find best practices have fallen flat.
I'm guessing that adding the same lineterminator argument to csv.writer in postgeo would fix the issue. Let me try that and see if it works.
@amikiri , what happens if you just try with rU and wb?
I tried with rU and w (no b) and got cr-cr-lf with no line terminator argument.
I pushed out a bunch of smallish fixes to postgeo.py in commit https://github.com/PalmBeachPost/postgeo/commit/f3d911144e110df1e32665b55e16ab0d4d121784 , but also tried the rU, wb, no terminator. Works here. No idea if it works on your end. I can test in Linux but don't have easy access to a Mac box.
The 'wb' causes an error in Python 3 because it's expecting a real bytes object not a string. However leaving off the 'b' worked fine (on my Mac). Did the lineterminator fix not work on your Windows machine?
I'm assuming this works properly in Python 3 else @amikiri wouldn't have submitted patch, but I haven't tested.