简体   繁体   中英

difference in mysql editor select query and python program select query result

I am executing a select query from python program to MySQL 5.2.39 database. But the result from mysql editor select query and python program select query is slightly different. Database name is world, table name is wordcount, it has 4 column: id, author, word,count. why those L suffix coming in python result ? can anybody tell what could be the reason ? even I have tried to put the whole long select query expression in single line in my python code but still same problem. I am using Eclipse with Pydev. Below is my python code :

import MySQLdb as mdb
import sys
con = mdb.connect('localhost', 'root', '1234', 'world')
con.autocommit(True)
with con: 
    cur = con.cursor()
    cur.execute("select author,count(distinct word),count(distinct id) from \
        world.wordcount \
        group by author \
        having count(distinct word)<> count(distinct id) \
        order by author")

    rows = cur.fetchall()
    for row in rows:
        print row

sample result from python :

('A  GONZ  LEZ', 18L, 19L)
('A  M  MORENO', 8L, 9L)

sample result from MySQL editor :

A  GONZ  LEZ|18|19
A  M  MORENO| 8| 9

They're the same values, even if the representation is different. When L is after a number in Python < 3, that means the number is a long , which is a specific type of number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM