Python中文
首页
教程
问答
标签
搜索
登录
注册
简单的PythonMySQL桥?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>在Python和MySQL之间有没有一个漂亮而简单的接口?我已经看过MySQLdb模块、SQLAlchemy和MySQL提供的模块。他们工作,但只是笨重和难以快速工作。我是Python的新手,但我在MATLAB中做过这个,而且它们有一个非常简单的界面。一、 E</p> <p>每次要用Python执行查询时,似乎必须执行以下操作:</p> <pre><code>import datetime import mysql.connector cnx = mysql.connector.connect(user='scott', database='employees') cursor = cnx.cursor() query = ("SELECT first_name, last_name, hire_date FROM employees " "WHERE hire_date BETWEEN %s AND %s") hire_start = datetime.date(1999, 1, 1) hire_end = datetime.date(1999, 12, 31) cursor.execute(query, (hire_start, hire_end)) for (first_name, last_name, hire_date) in cursor: print("{}, {} was hired on {:%d %b %Y}".format( last_name, first_name, hire_date)) cursor.close() cnx.close() </code></pre> <p>而在MATLAB中,我只启动一次连接(比如启动程序时,然后检索的内容很简单(<a href="http://www.mathworks.com/matlabcentral/fileexchange/8663-mysql-database-connector" rel="nofollow">from here</a>):</p> ^{pr2}$ <p>无需每次查询时创建游标和连接,只需一个简单的I/O查询执行器和数据返回器。我喜欢玩数据库,有很多跨平台的项目。能够在MATLAB中即时连接和查看数据是一个很棒的特性。有没有Python桥可以做到这一点?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>使用熊猫。它的界面很棒。看这里:</p> <p><a href="https://stackoverflow.com/questions/10065051/python-pandas-and-databases-like-mysql">python-pandas and databases like mysql</a></p> <p>我用它从python访问我所有的数据库。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
python语法错误(如果不在Z中,则在X中表示s)
6 回答
Python语法错误(无效)概率
3 回答
python语法错误*带有可选参数的args
7 回答
python语法错误2.5版有什么办法解决吗?
10 回答
Python语法错误2.7.4
7 回答
python语法错误30/09/2013
1 回答
Python语法错误E001
10 回答
Python语法错误not()op
10 回答
python语法错误outpu
7 回答
Python语法错误print len()
4 回答
python语法错误w3
4 回答
Python语法错误不是caugh
8 回答
python语法错误及yt-packag的使用
1 回答
python语法错误可以查出来!!瓦里亚布
1 回答
Python语法错误可能是缩进?
5 回答
Python语法错误和缩进
1 回答
Python语法错误在while循环中生成随机numb
7 回答
Python语法错误在哪里?
2 回答
python语法错误在尝试导入包时,但仅在远程运行时
4 回答
Python语法错误在电子邮件地址提取脚本中
7 回答