Quote:
Originally Posted by lomkiri
I trie
It's because it's pure python, not a regex-function.
From your messages, I understood that you knew a little about python, so it was made to be executed in the python command line or in the calibre-debug prompt, by a python program (in a file) or called in interactive mode.
|
I only know a little Python and I couldn't get the code to run in the interpreter. Then I got a little er... confused.
Anyway; I discovered what was wrong (syntax error in the json) and managed to get the dict method to work perfectly.
However when experimenting with my actual working file I found the massive size of the data in the find field somewhat unwieldy to say the least.
In the end I decided upon a simpler solution that also works as expected.
Find field:
Function:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
return match.group().replace('John','Mick').replace('George','Keith').replace('Paul','Ronnie').replace('Ringo','Charlie')
My working data file is in 2 columns of text so using Notepad++ in column mode I can easily add all the other punctuation and then remove the superfluous spaces. Its also easy to add/remove/change data then copy and paste into the function.
Many thanks for your input Lomkiri. Your time wasn't totally wasted as I learned a lot from your suggestions.