Matching Strings
Paul McGuire
ptmcg at austin.rr.com
Fri Feb 9 19:57:24 EST 2007
On Feb 9, 6:03 pm, rshep... at nospam.appl-ecosys.com wrote:
> I'm not sure how to change a string so that it matches another one.
>
> My application (using wxPython and SQLite3 via pysqlite2) needs to compare
> a string selected from the database into a list of tuples with another
> string selected in a display widget.
>
> An extract of the relevant code is:
>
> selName = self.polTree.GetItemText(selID)
> ...
> for item in self.appData.polNat:
> print 'Item: ', item, '\n', 'selName: ', selName, '\n'
> if item == selName:
> print '***** ', self.appData.polNat[1]
>
> The last comparison and print statement never work because the strings are
> presented this way:
>
> Item: (u'ground water',)
> selName: ground water
>
> What do I need to do to 'Item' to strip the parentheses, unicode symbol,
> single quotes, and comma? Do I want 'raw' output? If so, how do I specify
> that in the line 'if item == selName:'?
>
> TIA,
>
> Rich
I suspect that the variable item is *not* a string, but a tuple whose
zero'th element is a unicode string with the value u'ground water'.
Try comparing item[0] with selname.
>From my command prompt:
>>> u'a' == 'a'
True
-- Paul
More information about the Python-list
mailing list