02-22-2024, 07:46 PM | #1 |
Junior Member
Posts: 3
Karma: 10
Join Date: Feb 2024
Device: Kobo Aura One
|
Incorrect number of arguments for function
Hello everyone,
Let me preface this with: I have about 24 hours experience with Calibre templating language, so forgive me if I am missing something obvious. I have tried to search the forum and the internet, but found nothing. The problem I have written a function maketitle which takes in 6 arguments. For almost all books, it works perfectly, but for a few select cases I get the error Code:
EXCEPTION: Incorrect number of arguments for function maketitle Code:
def evaluate(self, formatter, kwargs, mi, locals, title, author, series, series_index, category, pairing): [...]
Debugging Since it is a basic template, I am running it on the field title Code:
{title:maketitle({author},{series},{series_index},{#category},{#pairing})} Code:
EXCEPTION: Incorrect number of arguments for function maketitle I have noticed 2 things:
I have also tested removing and adding fields, to see how many arguments it was effectively taking in. Removing 1 argument solved the issue for the 3 books. My conclusion was that, at least for the column in Calibre, the comma in the authors list is being interpreted not literally but as part of the code. Therefore it is separating "authors" into multiple arguments sent into the function. What I am looking for 1. Fields as literals (escaping)? My first instinct was that I needed to pass the field names as literals, so they don't get split into multiple arguments. I've tried the syntax Code:
{title:maketitle(`{author}`,{series},{series_index},{#category},{#pairing})} Code:
Incorrect number of arguments for function maketitle 2. Alternative way to use my Python functions in templates I don't know much about Calibre's templating system, so maybe there's an easier way to do this. I'm open to suggestions. All I want is to have my makefile function do its job, which is to determine the subdirectory where the book will be saved and establish which data goes into the title and which doesn't. I also want this to work for saving books to disk/device. |
02-23-2024, 06:25 AM | #2 | ||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I strongly recommend you look at the template language manual.
You are breaking a major rule for Single Function Mode: Quote:
Quote:
Code:
{title:'maketitle($, $author, $series, $series_index, $#category, $#pairing)'} |
||
02-23-2024, 04:02 PM | #3 | ||
Junior Member
Posts: 3
Karma: 10
Join Date: Feb 2024
Device: Kobo Aura One
|
First and foremost, THANK YOU for taking the time to help me.
Quote:
The problem is: I didn't really understand that rule, specifically on how I could avoid doing that, until you showed me the alternative. Quote:
I also must admit that, although I understand there are 3 different modes, I don't fully understand:
|
||
02-23-2024, 04:41 PM | #4 | ||||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
The manual has lots of examples of GPM templates that should help. Look at those and use the calibre Template tester to experiment. Quote:
Personally, I always use GPM or PTM to avoid syntax traps and task complexity outgrowing the other modes. Sometimes I use TPM that calls stored templates (Preferences / Advanced / Template functions) for the complex stuff and where I want to reuse the computation. Quote:
Code:
{tags} {#some_column:some_function()} {title:'maketitle($, $author, $series, $series_index, $#category, $#pairing)'} |
||||
02-23-2024, 05:29 PM | #5 |
Custom User Title
Posts: 8,639
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
@calibricious - just want to mention I love that username
|
02-23-2024, 05:43 PM | #6 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
BTW: the grammar is written in Extended Backus–Naur form.
Last edited by chaley; 02-23-2024 at 05:46 PM. |
02-23-2024, 06:16 PM | #7 | |
Junior Member
Posts: 3
Karma: 10
Join Date: Feb 2024
Device: Kobo Aura One
|
Quote:
Thank you so much for the answers! I really appreciate all the guidance (and special thanks for mentioning the Algol background + EBNF, it tickled my brain in all the right ways). Thank you As someone who is also owned by a cat, I must say: right back at ya |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Concatenate arguments in a replace function - Save to disk | Horus68 | Library Management | 2 | 10-03-2019 12:13 PM |
Random number in Regex Function? | nqk | Editor | 2 | 05-23-2017 11:47 PM |
Calibre 1.33 - incorrect version number? | massenz | Calibre | 1 | 04-20-2014 01:16 AM |
Nesting Function arguments in custom columns | da_jane | Calibre | 1 | 11-21-2012 02:48 PM |
Agency (ebook) pricing gone from arguments on MR to arguments in court. | RichL | News | 3 | 12-07-2011 07:40 AM |