首先安装SQLObject与python3 MYSQL接口
pip install sqlobject
pip install mysqlclient
就可以正常使用,如下:
from sqlobject import *
#mssql://user:pass@host:port/db
#mysql:///localhost/test?charset=latin1
conn = connectionForURI('mysql:///localhost/test?charset=latin1')
sqlhub.processConnection = conn
class Servers(SQLObject):
name = StringCol()
sex = StringCol()
#Servers.createTable()
Servers(name='tom', sex='男')
for i in range(200, 300):
Servers(name=str(i), sex='女')