how to map python 2.0 string opeartion to python 1.5.2 ?
Tim Roberts
timr at probo.com
Wed Apr 4 02:24:45 EDT 2001
ed_tsang at yahoo.com wrote:
> .......
>No idea how to replace these lines with 1.5.2 syntax:
> if caseInsensitive:
> # charMap[ord(fromValue.upper())] = toValue
> # charMap[ord(fromValue.lower())] = toValue
>replaced by:
> I don't know ...
charMap[ord(string.upper(fromValue))] = toValue
charMap[ord(string.lower(fromValue))] = toValue
> # self.charMap = "".join(charMap)
>replaced by:
> self.charMap = string.join("",charMap)
That's backwards:
self.charMap = string.join(charMap, "")
> if not wholeWords:
> # rePattern = '|'.join(map(re.escape, fromVals))
>replaced by:
> rePattern = string.join('|', map(re.escape,fromVals))
rePattern = string.join( map(re.escape,fromVals), '|' )
> else:
> # rePattern = r'\b(' + '|'.join(map(re.escape, fromVals))
>+ r')\b'
>replaced by:
> temp = string.join('|', map(re.escape,fromVals))
> temp = string.join(temp,r')\b')
> rePattern = string.join(r'\b(',temp) --- ???
The '+' operator works fine on strings in Python 1:
rePattern = r'\b(' + string.join(map(re.escape, fromVals),'|') + r')\b'
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list