Link to home
Start Free TrialLog in
Avatar of oaktrees
oaktrees

asked on

How to Edit This Python Script

Hi,

I can't figure out where and in what format to put the sorting parameters in this python code.

from .notes import isNew, isNotNew

nidToRand = dict()
def toTup(card, params):
    """A tuple to sort the card. See bothSched.sortCids to get more
    informations."""
    l = []
    for param in params:
        if isinstance(param, tuple):
            param, reverse = param
        else:
            reverse = False
        if param == "new first":
            val = (isNotNew(card.note()))#false occurs first in list
        elif param == "seen first":
            val = (isNew(card.note()))#false occurs first in list
        elif param in {"ord", "card position"}:
            val = (card.ord)
        elif param == "note creation":
            val = (card.nid)
        elif param == "card creation":
            val = (card.id)
        elif param == "mod":
            val = (card.note().mod)
        elif param == "note random":
            if card.nid not in nidToRand:
                nidToRand[card.nid] = random()
            val = nidToRand[card.nid]
        elif param == "card random":
            val = (random())
        if reverse:
            val = -val
        l.append(val)
    return tuple(l)

Open in new window


It is from here: https://github.com/Arthur-Milchior/anki_sort_cards
Avatar of noci
noci

What to edit?  Why to edit?

notepad, notpad++  or some other flat ascii file editor will do.

the code walks a list named params.....    for each param from the list it checks if is an item or tuple of: (param, reverse)  + string, boolean.

apparantly it determins a value val depending from cards/ random depending on param..      in the case of reverse ( a boolean) the value is negated.
It creates a list of values and returns that.
Avatar of oaktrees

ASKER

Hi,

You wrote:
WHAT TO EDIT?  WHY TO EDIT?

According to the script it seems it needs a tuple added.  I need to edit the script to add the tuple so it can execute correctly.  That's the why.

The "What to edit?" is actually my question.  I need to know where in the script that should go, and how it should be coded.

The Script Says
"""A tuple to sort the card. See bothSched.sortCids to get more
    informations."""

The Config Says
Configuration
The configuration is given by a list of parameter, separated by commas. (Technically, this is a json list, where the enclosings and are omitted.)

Sorting is done according to first parameter. In case of equality according to second parameter. And so on. A paramater is either a string "rule", or a pair ("rule", False). (Link)

Thanks!

OT
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial