.Q:
Python/Sqlite: Replace '||' with '/' when saving
Whenever I insert a string using.execute('insert into table..') I get the symbol '||' instead of '/'. I have tried to play around with.encode('utf-8') and.encode('utf-8').decode('latin-1') but nothing works.
#Adding
sqlite3.register_adapter(u'sqlite_c', lambda x: x.replace('|', '/'))
#Getting
r.execute('insert into table (col1, col2, col3) values (?,?,?)', (data1, data2, data3))
data1 = u'I'm a panda/kangaroo'
data2 = u'I'm a cow/kangaroo'
data3 = u'I'm a pig/kangaroo'
I would like the string to be saved as such: I'm a pig/kangaroo/
A:
SQLite uses Unicode, and as such, the | is a literal that means "OR". This behavior is documented in the source:
There are no database encodings which encode these characters, therefore they will be stored literally.
It's quite common to work around this, by replacing the | with some other character or string:
sqlite_c.execute('insert into table (col1, col2, col3) values (?,?,?)', (data1, data2, data3)).replace('|', '/')
Dorothy Wachen
Dorothy Wachen (c. 1937 – August 1, 2007) was an African-American journalist and librarian. She was known for her work at the University of Michigan Library and the Detroit Public Library. She was also active in the National Association of Black Journalists. She died of ovarian cancer in 2007.
References
External links
The Dorothy Wachen Papers, Wayne State University.
Category:2007 deaths
Category:African-American journalists
Category:American librarians
Category:Year of birth uncertain
Category:Wayne State University alumni
Category:People from Detroit
Category:African-American librariansThe present invention relates to an improved method of bonding semiconductor be359ba680
Related links:
Comentarios