quick regex question

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top