473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

str.title question after '

I have a text in ascii. I use the ' for an apostroph. The problem is
this gives problems with the title method. I don't want letters
after a ' to be uppercased. Here are some examples:

argument result expected

't smidje 'T Smidje 't Smidje
na'ama Na'Ama Na'ama
al pi tnu'at Al Pi Tnu'At Al Pi Tnu'at
Is there an easy way to get what I want?

Should the current behaviour condidered a bug?
My would be inclined to answer yes, but that may be
because this behaviour would be wrong in Dutch. I'm
not so sure about english.

--
Antoon Pardon
Nov 13 '06 #1
3 1183
Antoon Pardon wrote:
I have a text in ascii. I use the ' for an apostroph. The problem is
this gives problems with the title method. I don't want letters
after a ' to be uppercased. Here are some examples:

argument result expected

't smidje 'T Smidje 't Smidje
na'ama Na'Ama Na'ama
al pi tnu'at Al Pi Tnu'At Al Pi Tnu'at
Is there an easy way to get what I want?
Depends on your definition of "easy". Writing your own function that
will regard the apostrophe as a letter would be "easy" in my book.
>
Should the current behaviour condidered a bug?
Its limitations could use some documentation.
My would be inclined to answer yes, but that may be
because this behaviour would be wrong in Dutch. I'm
not so sure about english.
It's not very appropriate for English, either:

| >>"didn't".title()
| "Didn'T"

It's OK for the English way of writing Irish surnames e.g. O'Brien, but
not IMHO very good behaviour for anything else.

The docs say: "Return a titlecased version of the string: words start
with uppercase characters, all remaining cased characters are
lowercase." Evidently the definition of "word" is the culprit.

Doing titlecasing properly depends heavily on the language/locale and
what data you are working on. For example, in the UK and anywhere that
Scots have migrated in reasonable numbers, you would probably want to
do McDonald and MacDonald. Avoiding nonsenses like MacE and MacHin :-)
takes some effort and a look-up table, and may not be cost-effective.

A related problem: some people mistakenly try too hard to correct
perceived data entry errors and also produce nonsenses -- a colleague
of Dutch extraction occasionally received mail addressed to Mr O'Belt
:-)

Cheers,
John

Nov 13 '06 #2

Antoon Pardon wrote:
I have a text in ascii. I use the ' for an apostroph. The problem is
this gives problems with the title method. I don't want letters
after a ' to be uppercased. Here are some examples:

argument result expected

't smidje 'T Smidje 't Smidje
na'ama Na'Ama Na'ama
al pi tnu'at Al Pi Tnu'At Al Pi Tnu'at
Is there an easy way to get what I want?
def title_words(s):
words = re.split('(\s+)', s)
return ''.join(word[0:1].upper()+word[1:] for word in words)
>
Should the current behaviour condidered a bug?
I believe it follows definition of \w from re module.
My would be inclined to answer yes, but that may be
because this behaviour would be wrong in Dutch. I'm
not so sure about english.
The problem is more complicated. First of all, why title() should be
limited to human languages? What about programming languages? Is
"bar.bar.spam" three tokens or one in a foo programming language? There
are some problems with human languages too: how are you going to
process "out-of-the-box" and "italian-american"?

-- Leo

Nov 13 '06 #3
Leo Kislov wrote:
>Is there an easy way to get what I want?

def title_words(s):
words = re.split('(\s+)', s)
return ''.join(word[0:1].upper()+word[1:] for word in words)
nit: to work well also for Unicode strings using arbitrary alphabets,
you should use title() instead of upper(). a naive upper() will do the
wrong thing in some cases, as can be seen in the following example:
>>u = u"\u01C9"
unicodedata.name(u)
'LATIN SMALL LETTER LJ'
>>unicodedata.name(u.upper())
'LATIN CAPITAL LETTER LJ'
>>unicodedata.name(u.title())
'LATIN CAPITAL LETTER L WITH SMALL LETTER J'

</F>

Nov 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: runes | last post by:
Hi, I'm trying to set the title of the console window (CMD.EXE) in Windows. I want it set to the basename of the current directory and it should stay after the script has finished. Now, the...
6
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
50
by: MozillaCensorsMe | last post by:
Hello, While I haven't finished my wonderful tutorial to save the world, I do have a simple question. What's the difference between h1 and the title tag? For me it seems as though both can...
16
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET...
3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
9
by: Ian Renfrew | last post by:
Essentially, I want to prevent the display of the Microsoft Internet Explorer or any other branding tag in the document title. One technique that I've used is to insert multiple spaces after the...
5
by: Maxim Izbrodin | last post by:
Hello For displaying page titles for my ASP.NET applications I use the following technique <title><%=BannerModule.PageTitle%></title where BannerModule.PageTitle is a public field of my user...
8
by: Amir Sen | last post by:
Is it possible to dynamically change the IE title? After subsequent post back of the same page I would like to change the IE title which is to be read from a server side control (TextBox). ...
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
6
by: vijai.kalyan | last post by:
Hello, I wrote a trivial program to set the console title in a console application. Here is the code:- namespace myns { class SetTitle { static void Main ( string args )
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.