*[ Problem Solved ]* - Thanks James!

* http://www.sthurlow.com/python/lesson08/

* 
http://mypythonnotes.wordpress.com/2008/09/07/functions-and-boundunbound-methods/

* 
http://stackoverflow.com/questions/8108688/in-python-when-should-i-use-a-function-instead-of-a-method


#_______________________________________________________________________________

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

class AltwordManager(models.Manager):
    def dictfetchall2(self, p):
        "Returns all rows from a cursor as a dict."
        desc = p.description
        return [
            dict(zip([col[0] for col in desc], row))
            for row in p.fetchall()
        ]

    def vote_order(self):
        "Returns a 1:M list ordered by votes."
        cursor =  connection.cursor()
        cursor.execute("""
SELECT navi_polls_word.rosword
FROM navi_polls_altword
        """)
        #row = cursor.fetchall()
        #row = dictfetchall(cursor)
        row = AltwordManager.dictfetchall2(self, cursor)
        return row
#_______________________________________________________________________________










On Sunday, September 8, 2013 11:22:34 PM UTC+2, Pepsodent Cola wrote:
>
> Hi James,
>
> Ok will do!
>
>
>
> On Sunday, September 8, 2013 9:23:48 PM UTC+2, Pepsodent Cola wrote:
>>
>> I don't understand how to fix this error message?  Here is the code that 
>> made things break.
>>
>> Exception Value: global name 'dictfetchall2' is not defined
>>
>>
>>
>>
>> #_______________________________________________________________________________
>>
>> 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 dictfetchall2(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()
>>         ]
>>
>>     def vote_order(self):
>>         "Returns a 1:M list ordered by votes."
>>         cursor =  connection.cursor()
>>         cursor.execute("""
>> SELECT navi_polls_word.rosword
>> FROM navi_polls_altword
>>         """)
>>         #row = cursor.fetchall()
>>         #row = dictfetchall(cursor)
>> *        row = dictfetchall2(cursor)*
>>         return row
>>
>> ...
>> ...
>>
>> #_______________________________________________________________________________
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to