I have 675,000 strings to put in to mysql table. most of strings are normal words.
but some of strings are like below example of strings
- "kms\24""
- keyboard'
- 'someword'and
- "touch+\"someword\
- 24"monitor
- cleaner"150"
like this.
I can remove all \ from string. by make string to list and do
list_of_string = list(word)
for i in range(10) :
if """\\""" in list_of_string :
del list_of_string[list_of_string.index("""\\""")
but as you can see I can not replace or strip every " because there is some inch expression as at example number 5.
what I should do is remove " when it's number is mutiple of two. so i did
numb = list_of_string.count('"')
if numb % 2 == 0 :
for i in range(numb):
del list_of_string[list_of_string.index('"')
else :
for i in range(numb-1):
del list_of_string[list_of_string.index('"')
at last did
word = "".join(list_of_string)
now result is
- kms24"
- keyboard
- somewordand (I also removed all ' )
- touch+someword
- 24"monitor
- cleaner150
now, I need to put this word into mysql table what i did is
sql1 ='UPDATE {cat} SET {col} = "{val}" WHERE ind = "{ex}"'.format(cat=category, col=column, val=word, ex=index)
c.execute(sql1)
but as you expected, there is error. I can not put kms24" with above script.
anyone know how to force myspl to put string that has " in string?