Usually when I access db search results it's something like this:
cursor.execute( "select A1,A2,A3,A4 from B where C")
for (a1,a2,a3,a4) in cursor.fetchall ():
stuff()
But sometimes the point at which I use the data returned is not with the
search, and so having the ability to access the results as a dictionary
is more useful. I know that with MySQLdb I can open the connection and
have it return a dictionary, but when only one search out of all the
requests needs to be that way, it seems too much hassle to get a new
cursor just for that. Also, as a web developer that uses python, my
designers cognate "name.attribute " much easier than "name['attribute']"
and so I came up with this function to help us both out.
Let me know what you think. Could this be done simpler?
def convert_cursor( cursor):
'''Converts a cursor object with a result set in tuples to a list of
dicts, where the members of the keys are the field names, and the
values are
the field values.'''
fields = map(lambda x: x[0], cursor.descript ion)
class DictObj(dict):
'''
DictObj is a normal dictionary that allows you to access its members
via ``var[key]`` as well as ``var.key``.
'''
def __init__(self,d ic):
dict.__init__(s elf,dic)
self.__dict__ = self
return [DictObj(zip(fie lds,x)) for x in cursor.fetchall ()] 0 1059 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Sterling |
last post by:
After much futzing about with the XML/XSD for the
Search.Response, I had to resort to this...
PLEASE Tell me there is a better way!
private void ExecuteAQuery(string
strLookingForWhat)
{
// create the area service object
|
by: Jack-of-all-traits |
last post by:
This is a big problem and I really need help, no one seems to
know how to solve this problem.
I want to take the data from a record in a particular a field that
contains the names of generic products made up of 1 to 4 words
and search each record online, on a search engine such as the
google.com or altavista.com. Then also retain or record the
results given for the number of hits form the search engine
website... take the number of...
|
by: Mishu |
last post by:
I have a document log as Access 2000 database. Each record has a
corresponding pdf and txt file stored in the same folder as the
database. There is a hyperlink field that points to the corresponding
pdf - for record No. 10 this would be 010.pdf.
I need to be able to search the log by keyword. This is of course
easy within the database itself; however the log does not contain the
full text of the related document. Is there a way to,...
|
by: jquest |
last post by:
Hi Again;
I have had help from this group before and want to thank everyone,
especially PCDatasheet.
My database includes a field called HomePhone, it uses the (xxx)xxx-xxx
format to include area code.
When a customer calls, I currently use Ctrl F with the HomePhone field
highlighted. Then I enter the last 4 digits and use the find next option.
This is cumbersome, so I have tried several methods (including a macro)
using comand...
|
by: Stav |
last post by:
Hi there.
I'm working on an application that currently uses DAO to connect to an
Access 97 database. The database is created by and used exclusively by
the product to store search results and statistics during the
product's operation. The number of searches stored in one database
vary a lot (one user might only do 100 whilst another might do 1
million).
Once the search results have been stored, the product provides a
| |
by: Homey! |
last post by:
Hello all
I am new to Access.
I have imported data from an old FoxPro 2.x database.
This is probably the most basic function but I cant get a search box to
work. I need to search for company name and cant figure it out in access.
Tony (homey)
|
by: pic078 via AccessMonster.com |
last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files)
that remains stuck in task manager after exiting the application - you can't
reopen database after exiting as a result - I have read every post out there
and spent hours trying to figure out the problem with no success whatsoever -
I have constrained the problem to one form however, and I think it's hiding
somewhere in my code associated with this form, which is...
|
by: Webstorm |
last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost.
Here is the page I am working on:
http://www.knzbusinessbrokers.com/default.asp
I have 3 search critera that I need to use when querying the database. Right now it is only looking for a match on one of those dropdowns and not all 3. can anyone help?
Here is the code:
<form BOTID="0" METHOD="POST" action="businessforsale_interface/Results/test3.asp">
|
by: Brit |
last post by:
I have an ASP file that retrieves names from an Access database for 4 different categories of membership, which the visitor to the page selects (corporate, institutional, regular, or student). The DNS name is "cati", the names are specified in the "Last_names" field, and the categories are in the "categories" field.
l want the results sorted in alphabetic order by last name. However, the results appear to be in a totally random,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |