View Single Post
Old 07-03-2014, 08:20 PM   #514
Accel
Junior Member
Accel began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Sep 2013
Location: Moscow, Russia
Device: iPad
Thumbs down TEMPLATE ERROR: invalid conversion specification

Quote:
Originally Posted by eschwartz View Post
You have three () commas in that template. Commas separate arguments in the function. re() takes three arguments -- val, pattern, replacement -- and the first is inferred as author_sort from the template. (val is only used in general and template program mode, not single-function mode which is what we are using here). You have also left args 1 & 3 empty.
There is another formula and had the same result: ERROR
Of course, I read the manual. And did some help script on Python,
but still need help.
Why this template have an ERROR?

Spoiler:
Code:
# coding: utf-8

# if you have Python
# just run in terminal 'python re4calibre.py'

import re

print '\n'
print '\t For help use Online regex tester and debugger http://regex101.com/#python'


pattern = ur', ([^\s.])[^\s.]*(?:(?:$|\s|\.)+)'

replacement = ur', \1. '

str1 = u'Wood, Sir John & Vivekananda & Krisna, R. O. & Ball, Harry'
str2 = u'Wood, Sir & Warner, Brother'
str3 = u'Vivekanda & Shivananda'
str4 = u'Wood, Sir John & Vivekananda & McDonalds, G. B. & Warner, Brother & Braun'
str5 = u'Wood, Sir & McDonalds, Alex Jonathan'

print '\n'

print '\t1. '+str1+' -->'
print '\t   '+re.sub(pattern, replacement, str1, flags=re.I)
print '\t2. '+str2+' -->'
print '\t   '+re.sub(pattern, replacement, str2, flags=re.I)
print '\t3. '+str3+' -->'
print '\t   '+re.sub(pattern, replacement, str3, flags=re.I)
print '\t4. '+str4+' -->'
print '\t   '+re.sub(pattern, replacement, str4, flags=re.I)
print '\t5. '+str5+' -->'
print '\t   '+re.sub(pattern, replacement, str5, flags=re.I)

print '\n'
print 'Copy template for Calibre column:'
print '{author_sort:re('+pattern+','+replacement+')}'
print '\n'
Attached Files
File Type: zip re4calibre.zip (1.0 KB, 191 views)
Accel is offline   Reply With Quote