View Single Post
Old 10-10-2013, 09:42 PM   #9
kcz
Member
kcz began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Oct 2013
Device: Kindle
Quote:
Originally Posted by chaley View Post
You are conflating the template language and python, and also not importing the necessary python modules. When writing user defined functions you must use python and only python.
Hmm, this is interesting. I was using the code of other functions as a template.
e.g. look at the re function. Very strange.
On my installation the re function looks like this:

Code:
def evaluate(self, formatter, kwargs, mi, locals, val, pattern, replacement):
    return re.sub(pattern, replacement, val, flags=re.I)
This is all very confusing.

There are so many things that do not make any sense to me. Let's say I want to return either an integer or a float depending on the occurrences within a series. e.g. let's say there are 3 books in series x and the 2nd book has 1.50 as the index value, so a function should return a float in the format aa.bb for all the books in the series.

technically you would write a function which loops through all the books in a series and if one index is not an integer then return the current index as aa.bb (even if the current one is an integer like 2.00)

series x: book one - 1.00, book 2 - 1.50, book 3 - 3.00, so the function would return 01.00, 01.50, 03.00.
If the second book had an index of 2.00, then the function would return 01, 02, 03.
(the funcion is called once for every book in the series)

But I have no idea how to even reference the books in a series in python. Maybe this is not even possible. I'm used to code in C and thus would access the data via dynamic sql, ran the loop once and stored the result that one or more values are a float in shared memory. In that case I had a map which told me series x had a float or not.
whenever I call the function, it would check if an entry in the map existed and if not it'd use above routine to generate the entry in the map.
kcz is offline   Reply With Quote