Matching Strings
James Stroud
jstroud at mbi.ucla.edu
Fri Feb 9 19:17:31 EST 2007
rshepard 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
Assuming item is "(u'ground water',)"
import re
item = re.compile(r"\(u'([^']*)',\)").search(item).group(1)
James
More information about the Python-list
mailing list