Quote:
Originally Posted by chaley
The template code is:
Code:
python:
def evaluate(book, context):
import re
nt = []
for w in re.split(r'([ _.()])', book.get('title')):
nt.append(w.capitalize())
return ''.join(nt)
The r'([ _.()])' is the list of letters that separate words to be capitalized. This choice may not be the best for your library. You might want to add more letters. You could use r'(\W)', all non-alphabetic letters, but this might do the wrong thing with words like "_aaa" (aaa would not be capitalized) or "a.b" (b would not be capitalized). The choice depends on how much cleanup is required. Personally, I would use r'(\W)' and clean up the odd wrong title.
If you change the template you can test it on some books using the template editor before running it in Search & replace.[*]Press OK. Wait. Changing titles requires writing the disk, which can take some time.[*]Check the results. If they aren't what you want then restore the backup.[/LIST]
EDIT: This template uses the python title() function to "Return a titlecased version of the string where words start with an uppercase character and the remaining characters are lowercase." It does a better job in some cases but suffers from changing words like "isn't" to "Isn'T".
Code:
python:
def evaluate(book, context):
return book.get('title').title()
|
Hello, maybe you want to help me too.
I do (I think) exactly what it says and still it gives me the wrong result. What am I doing wrong?