1

In my csv file the data is separated by a special character. When I view in Notepad++ it shows 'SOH'.

ATT_AI16601A.PV01-Apr-2014 05:02:192.94752310FalseFalseFalse

ATT_AI16601A.PV[]01-Apr-2014 05:02:19[]2.947523[]1[]0[]False[]False[]False[]

It is present in the data but not visible. I have put markers in the second string where those characters are. My point is that I need to read that data in Python delimited by these markers. How can I use these special characters as delimiters while reading data?

martineau
  • 119,623
  • 25
  • 170
  • 301
Usama
  • 480
  • 4
  • 15
  • is that special character is ascii or non-ascii – nishant kumar Apr 25 '17 at 10:59
  • Possible duplicate of [How to split line at non-printing ascii character in Python](http://stackoverflow.com/questions/2936174/how-to-split-line-at-non-printing-ascii-character-in-python) – Ivan Apr 25 '17 at 11:00
  • @Ivan i am talking about csv delimeter. import csv with open('eggs.csv', 'wb') as csvfile: spamwriter = csv.writer(csvfile, delimiter='[]') – Usama Apr 25 '17 at 11:03
  • @nishantkumar it is an ascii control character with code 01 refrence http://www.theasciicode.com.ar/ – Usama Apr 25 '17 at 11:04
  • 2
    You should be able to read it with the `csv` module by specifying it as the delmiter: i.e. `reader = csv.reader(file, delimiter='\x01')` This is because `SOH` is an ASCII control character with a code point of `1`. – martineau Apr 25 '17 at 11:08

1 Answers1

2

You can use Python csv module by specifying , as delimiter like this.

import csv
reader = csv.reader(file, delimiter='what ever is your delimiter')

In your case

reader = csv.reader(file, delimiter='\x01')

This is because SOH is an ASCII control character with a code point of 1

Muhammad Hassan
  • 14,086
  • 7
  • 32
  • 54