tuple/string compare

Ari Davidow ari_deja at ivritype.com
Mon Oct 23 10:20:56 EDT 2000


 Well, here's one of those newbie confusions. I'm trying to compare
data from two sources. The first source goes to a database, fetches
what's there, and pops it into a dictionary, such that I get a tuple:

	crsr.execute("""
		select url from table
		where root_url = :1
		""", (myRootUrl,))

	myOldStuff = crsr.fetchall()

Then, I go read a page on the web with the URLs I need, use re to get
exactly the string I want, and I'm left with ... a string.

So, now, I'm trying to figure out if this new string matches a key in
the dictionary, and of course, there never is a match because the
string never matches the tuple:

('foo.html',)  is in the dictionary
foo.html      is my string, newUrl

		if myOldStuff.has_key(newUrl): print "bingo"
		else: pass

There must be a way to do this so that it works. Preferably, it seems
as though I should be able to retrieve the database material and save
it as a string into the hashtable. In fact, I do save the current root
URL successfully as a string:

(('/foo.html',):'www.bar.com')

if myOldUrls != []:
	for row in myOldUrls:
		allOldUrls[row] = myRootUrl

So, is there some way to make something work like:

if myOldUrls != []:
	for row in myOldUrls:
		allOldUrls[row] = myRootUrl
		row = just the string from the former, immutable tuple

or some better way to approach this?

--
Ari Davidow
ari at ivritype.com


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list