Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 05-30-2021, 07:43 PM   #1
sweth
Connoisseur
sweth began at the beginning.
 
Posts: 68
Karma: 10
Join Date: May 2015
Device: Kindle Fire 7 (7G), Kindle PW (2G), Kindle Scribe
Math functions in GPM

Is there any way to import python math functions for use in general program mode? eg log()
sweth is offline   Reply With Quote
Old 05-31-2021, 05:38 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by sweth View Post
Is there any way to import python math functions for use in general program mode? eg log()
Yes, by using User-defined Python template functions
chaley is offline   Reply With Quote
Advert
Old 05-31-2021, 06:12 PM   #3
sweth
Connoisseur
sweth began at the beginning.
 
Posts: 68
Karma: 10
Join Date: May 2015
Device: Kindle Fire 7 (7G), Kindle PW (2G), Kindle Scribe
I guess I phrased my question poorly. How would one import the math lib to a user-defined function?

Code:
program:
    import math
throws the exception

Quote:
EXCEPTION: Formatter: Expected end of program, found 'math' near 'import' on line 2
sweth is offline   Reply With Quote
Old 05-31-2021, 06:21 PM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by sweth View Post
I guess I phrased my question poorly. How would one import the math lib to a user-defined function?

Code:
program:
    import math
throws the exception
You didn't read/follow the documentation I linked to. You must create a user-defined python template function using the Template Functions tab found at Preferences / Advanced / Template Functions.
chaley is offline   Reply With Quote
Old 05-31-2021, 07:05 PM   #5
sweth
Connoisseur
sweth began at the beginning.
 
Posts: 68
Karma: 10
Join Date: May 2015
Device: Kindle Fire 7 (7G), Kindle PW (2G), Kindle Scribe
Quote:
Originally Posted by chaley View Post
You didn't read/follow the documentation I linked to. You must create a user-defined python template function using the Template Functions tab found at Preferences / Advanced / Template Functions.
Apologies; I thought that I had done exactly what you had suggested (which was also what I had done before posting originally, based on reading the docs).

It appears the disconnect is that the docs for creating template functions say to go to Preferences  →  Advanced  →  Template functions, but leave out the last step of then selecting the "Template functions" tab (which for some reason isn't the default for the template functions window); I missed the existence of that tab, and assumed based on the large bold "Template functions" header on the window that I was on the correct screen, so I was attempting to define a template function in what turns out to be the Stored Templates tab.
sweth is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template: unexpected result with gpm ownedbycats Library Management 5 03-16-2021 05:17 AM
New functions danielr KOReader 1 11-30-2019 02:56 AM
Arrays, capturing parens in GPM? sweth Library Management 2 09-29-2018 02:59 PM
Custom column GPM foobarius Library Management 3 09-04-2016 07:20 PM
New functions poco06 Calibre 4 05-01-2010 01:39 PM


All times are GMT -4. The time now is 07:27 PM.


MobileRead.com is a privately owned, operated and funded community.