Note that there are some explanatory texts on larger screens.

plurals
  1. POPython reading csv problem : extra whitespace
    text
    copied!<p>When I tried to parse a csv which was exported by MS SQL 2005 express edition's query, the string python gives me is totally unexpected. For example if the line in the csv file is :" aaa,bbb,ccc,dddd", then when python parsed it as string, it becomes :" a a a a , b b b , c c c, d d d d" something like that.....What happens???<br> I tried to remove the space in the code but don't work.</p> <pre><code>import os import random f1 = open('a.txt', 'r') f2 = open('dec_sql.txt', 'w') text = 'abc' while(text != ''): text = f1.readline() if(text==''): break splited = text.split(',') for i in range (0, 32): splited[i] = splited[i].replace(' ', '') sql = 'insert into dbo.INBOUND_RATED_DEC2010 values (' sql += '\'' + splited[0] + '\', ' sql += '\'' + splited[1] + '\', ' sql += '\'' + splited[2] + '\', ' sql += '\'' + splited[3] + '\', ' sql += '\'' + splited[4] + '\', ' sql += '\'' + splited[5] + '\', ' sql += '\'' + splited[6] + '\', ' sql += '\'' + splited[7] + '\', ' sql += '\'' + splited[8] + '\', ' sql += '\'' + splited[9] + '\', ' sql += '\'' + splited[10] + '\', ' sql += '\'' + splited[11] + '\', ' sql += '\'' + splited[12] + '\', ' sql += '\'' + splited[13] + '\', ' sql += '\'' + splited[14] + '\', ' sql += '\'' + splited[15] + '\', ' sql += '\'' + splited[16] + '\', ' sql += '\'' + splited[17] + '\', ' sql += '\'' + splited[18] + '\', ' sql += '\'' + splited[19] + '\', ' sql += '\'' + splited[20] + '\', ' sql += '\'' + splited[21] + '\', ' sql += '\'' + splited[22] + '\', ' sql += '\'' + splited[23] + '\', ' sql += '\'' + splited[24] + '\', ' sql += '\'' + splited[25] + '\', ' sql += '\'' + splited[26] + '\', ' sql += '\'' + splited[27] + '\', ' sql += '\'' + splited[28] + '\', ' sql += '\'' + splited[29] + '\', ' sql += '\'' + splited[30] + '\', ' sql += '\'' + splited[31] + '\', ' sql += '\'' + splited[32] + '\' ' sql += ')' print sql f2.write(sql+'\n') f2.close() f1.close() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload