M
Matt Price
hi folks,
this is surely trivial, but can'f figure it out. I wnat to replace:
'string with spaces'
with
'StringWithSpaces'
so I tried this:
s = 'string with spaces'
pat = ' (.)'
t = re.sub(pat, upper, s)
I know this isn't quite right, I expect it to return:
'String With Spaces'
instead I get an error:
t = re.sub(' (.)', upper, s)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sre.py", line 143, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/usr/lib/python2.3/string.py", line 64, in upper
return s.upper()
AttributeError: upper
what am I doing wrong?
matt
this is surely trivial, but can'f figure it out. I wnat to replace:
'string with spaces'
with
'StringWithSpaces'
so I tried this:
s = 'string with spaces'
pat = ' (.)'
t = re.sub(pat, upper, s)
I know this isn't quite right, I expect it to return:
'String With Spaces'
instead I get an error:
t = re.sub(' (.)', upper, s)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sre.py", line 143, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/usr/lib/python2.3/string.py", line 64, in upper
return s.upper()
AttributeError: upper
what am I doing wrong?
matt