Re: How can I add spaces where ever I have capital letters?

2008-05-09 Thread MRAB
On May 9, 3:04 am, "Eric Wertman" <[EMAIL PROTECTED]> wrote: > Something like this. I'm sure there are other ways to do it. > > import re > > def addspace(m) : > return ' ' + m.group(0) > > strng = "ModeCommand" > > newstr = re.sub('[A-Z]',addspace,strng) > Alternatively: newstr = re.sub

Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread John Schroeder
I do like one-liners and do not like regexps! That code puts mine to shame... Thanks for the tip. I'll use that one instead. On Thu, May 8, 2008 at 7:40 PM, Dan Bishop <[EMAIL PROTECTED]> wrote: > > On Thu, May 8, 2008 at 9:12 PM, John Schroeder <[EMAIL PROTECTED]> > wrote: > > > I have a stri

Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread Dan Bishop
> On Thu, May 8, 2008 at 9:12 PM, John Schroeder <[EMAIL PROTECTED]> wrote: > > I have a string (which I got from the names of my classes) and I would like > > to print out my CamelCase classes as titles. > > > I would like it to do this: > > my_class_name = "ModeCommand" > > ## Do some magic

Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread John Schroeder
Thanks guys. That upper() function reminded me to use the isupper() function. I got this going in a single pass: def a(name): self_name = name # Increment this value every time we add a space offset = 0 for i in xrange(len(name)): if i != 0 and name[i].isupper():

Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread Eric Wertman
Something like this. I'm sure there are other ways to do it. import re def addspace(m) : return ' ' + m.group(0) strng = "ModeCommand" newstr = re.sub('[A-Z]',addspace,strng) print newstr.strip() On Thu, May 8, 2008 at 9:12 PM, John Schroeder <[EMAIL PROTECTED]> wrote: > I have a

How can I add spaces where ever I have capital letters?

2008-05-08 Thread John Schroeder
I have a string (which I got from the names of my classes) and I would like to print out my CamelCase classes as titles. I would like it to do this: >>> my_class_name = "ModeCommand" ## Do some magic here >>> my_class_name 'Mode Command' Anyone know any easy way to do this? Thanks. -- http://ma