作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个将连接到数据库的 Python 脚本。数据库的主机 URL 以 jdbc 格式提供给我:
URL = jdbc:mysql://www.myurl.com:3306/
我不知道如何将该 URL 翻译成 pythonese。
如有任何帮助,我们将不胜感激。谢谢
import MySQLdb
conn = MySQLdb.connect(host="????",user="web3u4",passwd="password",db="web3db4")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close ()
# disconnect from server
db.close()
最佳答案
你应该使用 urlparse.urlparse
解析 jdbc 字符串。
from urlparse import urlparse
jdbc = "jdbc:mysql://www.myurl.com:3306"
result= urlparse(jdbc)
MySQLdb.connect(host=result.host,
user=result.username,
passwd=result.password,
db="web3db4")
不确定您打算如何传递数据库。但如果您添加它,我也可以帮助您。
关于python - 连接到 python 中的数据库 url,其中 url 用于 jdbc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8380909/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!