Python string.title Function

A

Allan

Hi All -

We're developing in Python 2.4.3 and are noticing something strange.
For example, when testing, here's what we're seeing:

x = "here's my title!";
x = x.title();
print x;
Here'S My Title!

Notice the capitalization -- "Here'S".
Any feedback on this issue is much appreciated.

Thanks much,
Allan
 
G

Georg Brandl

Allan said:
Hi All -

We're developing in Python 2.4.3 and are noticing something strange.

I'm noticing strange semicolons in your code... ;)
For example, when testing, here's what we're seeing:

x = "here's my title!";
x = x.title();
print x;
Here'S My Title!

Notice the capitalization -- "Here'S".
Any feedback on this issue is much appreciated.

str.title() isn't very sophisticated. It can't really make a difference
between an apostroph and a single quote.

If you need a better title(), I guess you'll have to write one yourself.

Georg
 
J

Jesse Hager

Try something like:

def capwords(words):
return ' '.join([x.capitalize() for x in words.split()])

capwords("here's my title!")
"Here's My Title!"
 

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

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,183
Latest member
GarfieldBa

Latest Threads

Top