db = pymysql.connect(host='192.168.89.41', user='root', passwd='root123', port=3306)
cur = db.cursor()
try:
cur.execute('show databases;')
data = cur.fetchall()
result1 = "('mysql',)" in data
result2 = "mysql" in data
result3 = "(\'mysql\'\,)" in data
result4 = "(\'mysql\',)" in data
print(data)
print(result1)
except:
print("操作 Mysql 失败")
print(data)的输出:
(('information_schema',), ('forum',), ('mysql',), ('mytest',), ('netdisk',), ('network',), ('save_sth',))
print(data[2])
('mysql',)
result1 到 4 的方式都是 False,我错在哪里?
1
stamaimer 2018-08-30 00:51:10 +08:00 via iPhone
data 中的元素都是 tuple,没有一个字符串。
|
2
msg7086 2018-08-30 01:59:43 +08:00
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux >>> data = (('information_schema',), ('forum',), ('mysql',)) >>> data (('information_schema',), ('forum',), ('mysql',)) >>> result2 = ('mysql',) in data >>> result2 True >>> |
3
imn1 2018-08-30 07:25:28 +08:00
result1 = "('mysql',)" in data
我一直在想哪个弱类型语言可以这样判断,好像 PHP 也不行吧? |
4
pppguest3962 OP |