dictfetchall(cursor) - What kind of sorcery is this?

1,270 views
Skip to first unread message

Pepsodent Cola

unread,
Sep 4, 2013, 3:55:13 PM9/4/13
to django...@googlegroups.com
I borrowed the dictfetchall(cursor) code directly from Djangoproject.com and it works with my code.
But what kind of sorcery is this?  How can I output the contents of desc?  I want to see what that data looks like.

    desc = cursor.description

Because I can't follow what's going on here.

    for col in desc

#_______________________________________________________________________________

def dictfetchall(cursor):
    "Returns all rows from a cursor as a dict."
    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]
#_______________________________________________________________________________

class AltwordManager(models.Manager):
    def vote_order(self):
        "Returns a 1:M list ordered by votes."
        cursor =  connection.cursor()
        cursor.execute("""
SELECT navi_polls_word.rosword, navi_polls_altword.alt_ros_word, navi_polls_altword.votes
FROM navi_polls_altword INNER JOIN navi_polls_word
ON (navi_polls_altword.rosword_id=navi_polls_word.id)
        """)
        #row = cursor.fetchall()
        row = dictfetchall(cursor)
        return row
#_______________________________________________________________________________

Masklinn

unread,
Sep 4, 2013, 4:07:26 PM9/4/13
to django...@googlegroups.com

On 2013-09-04, at 21:55 , Pepsodent Cola wrote:

> I borrowed the dictfetchall(cursor) code directly from Djangoproject.com
> and it works with my code.
> But what kind of sorcery is this? How can I output the contents of *desc*?
> I want to see what that data looks like.
>
> *desc* = cursor.description

Have you tried just printing it out?

Not that you need to,
http://www.python.org/dev/peps/pep-0249/#description will tell you what
`cursor.description` is.

Pepsodent Cola

unread,
Sep 4, 2013, 4:21:31 PM9/4/13
to django...@googlegroups.com
Thanks for the link I will study it.

But I still would like some help with printing and visualizing that "desc" data just to make sure it's not Voodoo.  :)
I don't really know how to print that out, MVC is confusing me.  Can you give me a hint which file I need to input my "print desc" LOC?

models.py , views.py or my html template file?
Reply all
Reply to author
Forward
0 new messages