Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 06-04-2023, 02:20 PM   #1
DyckBook
Morlock
DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.
 
DyckBook's Avatar
 
Posts: 33
Karma: 2734796
Join Date: Oct 2021
Device: Kindle Paperwhite
Roman to Arabic

I found this regex function on this forum and it worked at the time. Now it works the first time, and every time I open the edit function window, even without making changes, and thereafter returns 0. I'm not enough of a coder to know why. Could anyone please help?

The originally posted function had
n = unicode(n).upper(),
which I changed to
n = str(n).upper()
in order to make it work then. I understand that that was because of changes to Python. Could it be that Python has changed again?

Code:
numeral_map = zip(
    (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
    ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)
	   
def arabic_num(n):
    n = str(n).upper()
    i = result = 0
    for integer, numeral in numeral_map:
        while n[i:i + len(numeral)] == numeral:
            result += integer
            i += len(numeral)
    return result
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return match.group(1)+str(arabic_num(match.group(2)))+match.group(3)
DyckBook is offline   Reply With Quote
Old 06-04-2023, 05:37 PM   #2
DyckBook
Morlock
DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.
 
DyckBook's Avatar
 
Posts: 33
Karma: 2734796
Join Date: Oct 2021
Device: Kindle Paperwhite
I found the answer to my question, thanks to AI.

The lines:
numeral_map = zip(
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)

Needed to be replaced with this:

numeral_map = list(zip(
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
))

The function is working again and saving lots of fiddly work.
DyckBook is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
i need german:arabic and french arabic and italian arabic takfarinas Kobo Reader 3 02-14-2021 07:12 AM
Arabic to Arabic dictionary for Kobo hapaahamza Kobo Reader 1 09-04-2019 03:58 PM
Convert Roman numerals to Arabic? Peter W Sigil 2 04-09-2012 11:55 AM
PRS-900 Times New Roman and PDF vxf Sony Reader 2 06-18-2010 09:02 AM
Non-roman fonts ebookworm Sony Reader 6 10-06-2007 12:12 AM


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


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