Digital Index Card learning aid program

General Tech Learning Aids/Tools 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

The following code is a digital index card system to be used as a learning aid.

The index consists of key-value pairs which can be added, removed or replaced from the command line. Data is stored as a pickled object and formatted data is written to a .txt file for easy viewing/ searching.

This is derived from a function based script which utilised a dict to store the data; I've recently delved into OOP and I'm struggling a bit.

Example usage at command line:

C:\Users\Dave\Desktop\2016Coding>indexcards add "example key" "example value/ definition"

Added entry 'example key' and it's value.

*****Done*****

.txt file sample:

                              Python Index Cards                              



A

aa                                   --     dada das

aaaa                                 --     sdfs fdsfds f dsfds fsd fds  fdsf
                                            sf dsfs  fdsfwsed ffds dsfs fdssd
                                            fdsfsdf  dsffdsf sdf ds

aadasdasd dasdsa dasdas dasda        --     dada das
sdaw asdas da da ad da dasd                                                                       
dasdasd  dadas asd                                                              

addd                                 --     erewrwer iuoj



B

Code:

#!/usr/bin/env python3

"""
"""

import argparse
import bisect
from functools import total_ordering
import logging
import os
from operator import attrgetter
import pickle
import sys
from string import ascii_lowercase
from textwrap import wrap

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s - %(levelname)s - %(message)s")
#logging.disable(logging.CRITICAL)


@total_ordering
class Entry(object):
    """Responsible for holding and formatting a key-value pair"""

    def __init__(
        self,
        key,
        value,
        index_letter=False
        ):

        self.key = key
        self.value = value
        self.index_letter = index_letter
        self.full_entry = None

    def __eq__(self, object):
        return all((
            self.key == object.key,
            self.value == object.value
            ))

    def __lt__(self, object):
        return self.key < object.key

    def format_entry(
        self,
        page_width,
        key_max_width,
        value_max_width,
        separator,
        right_separator_spacing,
        left_separator_spacing
        ):
        """Format entries for insertion into Index"""

        if self.index_letter:
            # add whitespace above/below and capitalise letter
            self.full_entry = "\n\n" + self.key.title() + "\n\n"
        else:
            # set key, value to a list of line(s) of max width
            self.key = wrap(self.key, key_max_width)
            self.value = wrap(self.value, value_max_width) 

            # ensure key, value lists are of equal length for file writing
            
                                                
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.