We help IT Professionals succeed at work.

How to Edit This Python Script

oaktrees
oaktrees asked
on
82 Views
Last Modified: 2020-04-13
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
Comment
Watch Question

nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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.

Author

Commented:
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
Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.