In fact let me extend off this a little further. If I was to provide a code and documentation patch, which allows for an easy way to return back values with their field names (via a simple field_names=True), would you guys be willing to consider it for the core?
Cal On Thu, Jun 16, 2011 at 6:07 PM, Cal Leeming [Simplicity Media Ltd] < cal.leem...@simplicitymedialtd.co.uk> wrote: > @Andy / @ Alex: > > Yup, I know how to get this, but the point is, it took me 30 minutes of > searching to find this information out. > > What I'm asking, is for consideration of an *EASY* way to get this format, > via something like cursor.fetchall(field_names=True), or > cursor.dictfetchall(), and for that feature to be well documented. > > > > On Thu, Jun 16, 2011 at 4:42 PM, Andy Dustman <farcep...@gmail.com> wrote: > >> You can do something like: >> >> for row in cursor: >> dictrow = dict( (d[0], c) for d, c in zip(cursor.description, row) ) >> >> (izip may be better than zip. Your call.) >> >> Or for the whole result set: >> >> result = [ dict( (d[0],c) for d, c in zip(cursor.description, row) ) >> for row in cursor ] >> >> On Thu, Jun 16, 2011 at 10:03 AM, Cal Leeming [Simplicity Media Ltd] >> <cal.leem...@simplicitymedialtd.co.uk> wrote: >> > Okay, let me put it another way. >> > Are there any plans to give developers an easy way to retrieve values >> from a >> > cursor.fetchall(), in a DictCursor style? >> > Default: ((Decimal('0'), Decimal('52'), Decimal('4159'), 9998L),) >> > What I'm looking for: >> > [{ >> > 'f1' : Decimal('0'), >> > 'f2' : Decimal('52'), >> > 'f3' : Decimal('4159'), >> > 'f4' : 9998L >> > }] >> > Maybe something like cursor.fetchall(field_names=True), or >> > cursor.dictfetchall() - which is what the removed function did. >> > Cal >> > On Thu, Jun 16, 2011 at 2:54 PM, Luke Plant <l.plant...@cantab.net> >> wrote: >> >> >> >> On 16/06/11 14:10, Cal Leeming [Simplicity Media Ltd] wrote: >> >> > Okay, er. >> >> > >> >> > In reference to the original problem (cursor's not default to >> >> > DictCursor), thus no field names are returned, is there a specific >> >> > reason for this? If not, I'll probably raise a ticket to have it >> >> > considered for change. >> >> >> >> I'm not sure exactly what you are asking, because this is about default >> >> behaviour. The choice of a default is usually made according to what is >> >> thought to be the most useful, or according to the way it happens to >> >> have been done in the past. >> >> >> >> I also don't know what exactly you are suggesting. Our backwards >> >> compatibility policy means that we aren't going to change the default, >> >> unless other people's code is going to work transparently (which >> >> wouldn't be the case here), so it doesn't really matter what the >> >> original reason was, if there was one. If you are suggesting that we >> add >> >> some functionality to make use of DictCursor more useful, then >> certainly >> >> the suggestion is valid. >> >> >> >> Regards, >> >> >> >> Luke >> >> >> >> -- >> >> The probability of someone watching you is proportional to the >> >> stupidity of your action. >> >> >> >> Luke Plant || http://lukeplant.me.uk/ >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups >> >> "Django developers" group. >> >> To post to this group, send email to >> django-developers@googlegroups.com. >> >> To unsubscribe from this group, send email to >> >> django-developers+unsubscr...@googlegroups.com. >> >> For more options, visit this group at >> >> http://groups.google.com/group/django-developers?hl=en. >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "Django developers" group. >> > To post to this group, send email to django-developers@googlegroups.com >> . >> > To unsubscribe from this group, send email to >> > django-developers+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/django-developers?hl=en. >> > >> >> >> >> -- >> Question the answers >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers" group. >> To post to this group, send email to django-developers@googlegroups.com. >> To unsubscribe from this group, send email to >> django-developers+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-developers?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.