[英]modifying the contents of the sqlilte database
我有以下sqlite3數據庫:
name : sampledb
table : main
fields : id, name description and gender
樣本元素是:
"1" "John" "Fat-Head" "M"
我大約有2000行,並且想要從每個字段值中刪除引號,以便我的db元素如下所示:
1 John Fat-Head M
什么是有效的方法?
謝謝。
我不確定這是否會達到百分之一百,還是非常有效,請嘗試以下操作:
import sqlite3
db = sqlite3.connect('sampledb')
c = db.cursor()
new_set = []
c.execute('select * from main')
temp_value = []
for row in c:
for item in row:
temp_value.append(item[1:-1])
new_set.append(temp_value)
temp_value = []
# place it back into the database
希望這足以作為指導方針!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.