Python3.0中的SQL?

2024-05-16 12:47:32 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用任何SQL数据库,例如mysql、pgsql或Python内置支持的数据库除外?在

def example():
  con= Mysql("root", blablabla)
  con->query("SELECT * bla bla bla")
....

Tags: 数据库sqlexampledefmysqlrootquerycon
2条回答

这里有一个python3.x兼容包的列表:http://pypi.python.org/pypi?:action=browse&c=533&show=all

我只能找到oursql和{a3}

你在用什么分机?对于sqlite3(以及与DB-API 2.0兼容的任何其他扩展),您可以使用类似于this的东西:

conn = sqlite3.connect('/tmp/example')
c = conn.cursor()

# Create table
c.execute('''create table stocks(date text, trans text, symbol text, qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")

# Save (commit) the changes
conn.commit()

# We can also close the cursor if we are done with it
c.close()

顺便说一句,Python中没有->

相关问题 更多 >