On Thu, Jan 24, 2019 at 11:47 AM Jim Oberholtzer
<midrangel@xxxxxxxxxxxxxxxxx> wrote:

Still, others chasing the same question should get an answer to the original
question.

The "best" answer in Python, where I'm defining "best" as a fuzzy mix
of "handles the most cases the most accurately, while writing the
least amount of code yourself" would use the third-party nameparser
package I mentioned before, and go something like this

###
import sys
from nameparser import HumanName

name = HumanName(sys.argv[1])
name.capitalize()
print(name)
###

The above is written as though you will (1) treat the Python code as a
standalone script, rather than as a module, (2) call that script with
a single parameter which contains the entire name to be capitalized,
and (3) want the output to go to stdout.

So there are now at least three actual Python examples, in this
thread, for the exact question expressed in the subject line; and this
one should produce results that are similar to the PHP code that Jon
Paris linked to, and in most cases better than any of the naive
functions that are included with SQL, PHP, Python, or anything else
you care to name.

It's not really possible to get 100% accuracy, even in principle,
because two different people with the exact same letters in their
name, in the exact same order, will capitalize their name differently.
This would thwart even the lookup-table-for-special-cases approach.
For example, I have seen some people write their own surname MacLean,
while other people write their own surname Maclean.

So some people espouse leaving everything in all caps (everyone is
treated equally, and the postal service is happy). Others specifically
prefer the naive (first-letter-only) capitalization, because it's
obvious how it works, and people whose names are tripped up by this
are probably used to seeing their name mangled in this obvious way.

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.