0

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

1 Answer 1

1

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.

2
  • Ok, yes I am using Python 2.7, now hopefully this long format is for display purpose only or it is applied to data, I mean if I want to insert this select query result to another output-like suitable table, then those two column type have to be long or integer will work ?
    – pmr
    Commented May 7, 2013 at 19:49
  • Just make sure you cast using str and not repr and you'll be fine. Commented May 7, 2013 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.