您还可以使用pyodbc从Python连接到MSSQL。
文档中的示例:
import pyodbccnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATAbase=testdb;UID=me;PWD=pass')cursor = cnxn.cursor()cursor.execute("select user_id, user_name from users")rows = cursor.fetchall()for row in rows: print row.user_id, row.user_name所述的SQLAlchemy文库(在另一个答案提到的),用途pyodbc连接到MSSQL数据库(它会尝试各种库,但pyodbc是优选的)。使用sqlalchemy的示例代码:
from sqlalchemy import create_engineengine = create_engine("mssql://me:pass@localhost/testdb")for row in engine.execute("select user_id, user_name from users"): print row.user_id, row.user_name


