Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PyMySQL到Python的数据处理_Python_Mysql_Pymysql - Fatal编程技术网

PyMySQL到Python的数据处理

PyMySQL到Python的数据处理,python,mysql,pymysql,Python,Mysql,Pymysql,我正试图通过python从MySQL获取一个数字——我需要在以后的操作中使用这个数字。但我不太明白如何只抓住号码 使用PyMySQL: with connection.cursor() as cursor: # Read a single record sql = "SELECT 'data' FROM DB ORDER BY ID DESC LIMIT 1" cursor.execute(sql) result = cursor.

我正试图通过python从MySQL获取一个数字——我需要在以后的操作中使用这个数字。但我不太明白如何只抓住号码

使用PyMySQL:

with connection.cursor() as cursor:
        # Read a single record
        sql = "SELECT 'data' FROM DB ORDER BY ID DESC LIMIT 1"
        cursor.execute(sql)
        result = cursor.fetchall()
        print(result)
打印时总是返回{'ID:101,'data':1},我只希望将#1作为整数读入python

我已经尝试使用列表索引来选择它,但是我得到了一个关键错误

非常感谢您的帮助。

您试过了吗

number=result['data']
我建议您使用iPython或Jupiter笔记本来探索数据结构,以便以交互方式操作它们

或者使用像PyCharm这样的GUI来帮助您解决这个问题。

我已经解决了这个问题

  • 从SELECT语句后删除“”,它只是返回列标题
  • 使用str()函数
  • 然后使用.contains搜索我在后面的if语句中用作标记以激活特定大小写的整数