本文整理匯總了Python中db.DB.open方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.open方法的具體用法?Python DB.open怎麽用?Python DB.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.open方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import open [as 別名]
def main(args):
DB.open('data.db')
app = Qt.QApplication(args)
w = MainWindow()
w.show()
sys.exit(app.exec_())
示例2: len
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import open [as 別名]
from db import DB
import sys, os
if __name__ == '__main__':
if len(sys.argv) < 3 or sys.argv[1] == '-h':
print 'usage: dumpdb.py [all|attrs|data] [database]'
sys.exit(1)
if not os.path.exists(sys.argv[2]):
print >>sys.stderr, 'file', sys.argv[2], 'does not exist'
sys.exit(1)
db = DB()
db.open(sys.argv[2])
if sys.argv[1] == 'attrs' or sys.argv[1] == 'all':
for name, vals in sorted(db.attrs().items()):
print name[1] + ':' + ','.join(vals)
if sys.argv[1] == 'data' or sys.argv[1] == 'all':
for row in db.data():
print ','.join(row)
示例3: len
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import open [as 別名]
# if all the data classes are the same, then just return that classification
if classes.count(classes[0]) == len(classes):
return classes[0]
best = choosebest(data, attrs)
tree = { best.name: { } }
for val in best.vals:
newdata = [a for a in data if a[best.num] == val]
newattrs = [a for a in attrs if a.num != best.num]
tree[best.name][val] = gentree(newdata, newattrs)
return tree
import sys
from bz2 import BZ2File
import cPickle as pickle
from db import DB
if __name__ == '__main__':
if len(sys.argv) < 3 or sys.argv[1] == '-h':
print 'usage: gentree.py [database] [tree]'
sys.exit(1)
db = DB()
db.open(sys.argv[1])
tree = gentree(db.data(), db.attrs())
f = BZ2File(sys.argv[2], 'wb')
pickle.dump(tree, f, 2)
f.close()
示例4: Counter
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import open [as 別名]
#!/usr/bin/env python3
# -*- coding: utf-8 *-*
from db import DB
from counter import Counter
from recording import Recording
import datetime
import os
DB.open('example.db')
#### Add some counters
elec = Counter("Electricité")
elec.insert()
print(elec)
gaz = Counter("Gaz")
gaz.insert()
print(gaz)
print("")
#### List all the counters
print("List all : ")
allcounters = Counter.findAll()
for c in allcounters:
print(str(c))
示例5: Exception
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import open [as 別名]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from db import DB
import sys
import os
if(len(sys.argv) != 2):
raise Exception("Usage : %s filename.db" % sys.argv[0])
filename = sys.argv[1]
os.system("rm -f %s" % filename)
DB.open(filename)
DB.doUpdate("create TABLE counters (id integer primary key, name text)")
DB.doUpdate("create table recordings (id integer primary key, idcounter int, date text, value int)")
DB.close()