Quantcast
Channel: W3LC - World Wide Web Learners Consortium
Viewing all articles
Browse latest Browse all 108

CSV delimiter linux Vs Mac : Resolving the issue of comma separated file read and write

$
0
0
Excel allows CSV that is Comma Separated Values in its filesystem. It uses comma as a delimiter.
And, this format is often used for exchanging data between programs. But there comes issues while working on different operating systems.


As per my research, there could be three versions of CSV formats included with Excel:


  • CSV (Comma delimited) (*.csv)
  • CSV (Macintosh) (*.csv)
  • CSV (MS-DOS) (*.csv)
The main difference arises because on a Macintosh each record (each line in the file) is terminated with a carriage return, as expected by the Mac. In the Windows, lines are terminated with a carriage return and line feed combination (CRLF). This can mess things up on the Macintosh.


Example suppose you are using Python for CSV Reader or writer mechanism then you should take care of two points:

1. use wb mode in file processing.

https://docs.python.org/2/library/csv.html#csv.writer


If csvfile is a file object, it must be opened with the ‘b’ flag on platforms where that makes a difference.

That is,  where you are writing file, open in binary format - wb mode
And, when reading - use rb mode

2. Use proper line separator. Better to use os.linesep



Even in viewing file also, you can do the difference if it is only a one time change:


Open your csv file with WPS Spreadsheets

Select the A column -> Data -> Text to Columns -> Next -> Select or define your delimiter -> Finish


You can also view a related post:

Cheers ;)

By the way I quit smoking. Did you know?

Viewing all articles
Browse latest Browse all 108

Trending Articles