diff --git a/README b/README deleted file mode 100644 index 3a67110..0000000 --- a/README +++ /dev/null @@ -1,3 +0,0 @@ -A CheckList program in Python/GTK, using YAML for storage. Aimed at non-mobile users. - -This program will have three components: The checklist engine, a GUI version, and a command line utility. The GUI and the CL will both use the engine as their underlying method of performance and will read the same files. The actual checklists will be stored in YAML files for readability. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c02809f --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# PyChecklist +## Its the final CheckList +### A 'written in python for python' program in Python/GTK, using YAML for storage. Aimed at non-mobile users. + + +## This program will have three components: +1. The checklist engine +2. Graphical User Interface (GUI) version +3. Command Line Utility (CLU) + +The GUI and the CL will both use the engine as their underlying method of performance and will read the same files. The actual checklists will be stored in YAML files for readability. + + +## Update +1. Updated format and layout of PyChecklist +2. Renamed CheckList to PyChecklist for clarity. +3. Updated print statements with parenthesis's +3. Monkey patched an import statement and it works. \ No newline at end of file diff --git a/checkBuilder.py b/checkBuilder.py index 23dbd6f..1b729f2 100644 --- a/checkBuilder.py +++ b/checkBuilder.py @@ -25,14 +25,15 @@ def information(self): 'A formatted description of this item' return checkItem.template.format(self.title, self.created, self.due, self.priority, self.description) - + + class checkList(object): 'A list of tasks that need to be completed' def __init__(self, *items): self.items = [] #the list of checklist items if len(items) == 1: temp = items[0] - print temp + print(temp) elif len(items) > 0: for i in items: - print i + print(i) diff --git a/commands.py b/commands.py index 1c583d6..2e31915 100644 --- a/commands.py +++ b/commands.py @@ -10,9 +10,9 @@ from os.path import exists from datetime import date -#Eliminates the magic string "current"! +# Eliminates the magic string "current"! current = "current" -helpDoc ="""\ +helpDoc = """\ Checklist creates, displays, and controls lists of tasks. It's used for things like To-do lists or instructions. Commands: @@ -45,99 +45,105 @@ help help help add """ -curList = [] #the current check list +curList = [] # the current check list -def newCheckList(name='NewList'): + +def newCheckList(name="NewList"): """ Returns a new, empty checklist. Alias: new - + name -- the name of the new checklist. (Default: "NewList") - + Usage: newCheckList "tuesday" -- creates list "tuesday" new -- creates a new list called "NewList" - """ + """ return checkBuilder.checkList() - + + def loadCheckList(fp): """ Loads a checklist from a YAML file. Alias: load - + fp -- the identifier of the file. - + fp can either be the filename ("checklist.yaml"), the path to the file ("Lists/checklist.yaml"), or the name of the checklist ("checklist"). Since the checklist files are named after the checklist they hold, this is rather simple to implement. - + Usage: load tuesday -- sets "tuesday" as current list """ if exists(fp): - print "Will now load file---filename or filepath!" + print("Will now load file---filename or filepath!") else: - print "Now we would check for a checklist of the same name as file" + print("Now we would check for a checklist of the same name as file") return exists(fp) - + + def saveCheckList(): """ Saves a checklist in a YAML file. Alias: save - + The file will be named after checklist and stored in the local dir, ~/.checklists. On Windows, it would be AppData/.../.checklists. - + Usage: save -- saves the current list - """ + """ return "It would be saved in the YAML format in a file nearby" - + + def addItem(item, clist=current, idx=0): """ Adds a new task to a checklist. Alias: add - + item -- the item to add, a CheckItem object. clist -- the name of the checklist to add item to. idx -- the index to add the item at. - + item is the only required argument. If clist is not provided, - it is assumed that the item should be appended to the current list. + it is assumed that the item should be appended to the current list. Checklists are 1-indexed, so a 0 index indicates that it should be appended to the list. - + Usage: add newItem tuesday 5 -- adds the newItem to "tuesday" at index 5 """ return "Item appended!" - + + def remove(idx=0, clist=current): """ Removes the item at index i from the given checklist. - + idx -- the index of the item to remove. clist -- the list to remove the item from. - + If clist is absent, the current list is assumed. If idx is missing, it's assumed that the first item is removed. If idx = '*', the list is cleared. if idx = 'list', the list itself is deleted. - + Usage: remove -- removes the first item from current list remove list tuesday -- deletes "tuesday" """ return "Deletes items or a checklist!" + def clean(target="*all", clist=current): """ Removes overdue and completed items from a checklist. - + target -- what to clean up clist -- the checklist to clean. Default: current - + Possible values for target: - *all - *old @@ -145,17 +151,18 @@ def clean(target="*all", clist=current): *fin removes all completed items. *old removes all overdue items. *all removes both completed and overdue items. - + Possible values for clist: - a checklist identifier - *all *all will clean every checklist that this program manages. - + usage: clean *all clean *old tuesday --removes overdue items from the list 'tuesday' """ + def listItems(clist=current): """ Displays the checklist in a well-formatted YAML list. @@ -165,17 +172,18 @@ def listItems(clist=current): - what do?? """ return "The well-formatted items would be displayed here" - + + def getInfo(idx=0, clist=current): """ Displays information about a given item or list. Alias: info - + idx -- the index of the item to investigate clist -- the list that holds the item - + If idx = 'list' or 0, print information about the list. - + Usage: info list -- prints information about current list info list "tuesday" -- prints info about "tuesday" @@ -183,24 +191,26 @@ def getInfo(idx=0, clist=current): """ return "The item information is selected by index" + def editItem(idx): """ Edits the item at index i of the current list. NOT IMPLEMENTED. """ return "An interactive editing mode would start" - + + def nextDue(clist=current): """ Displays the information of the item that is due soonest. Alias: next - + clist -- the list to check for items. Default: "current" - + If clist = "*all", every list is checked to find the item due soonest. Finds the item is due nearest to datetime.date.today. - + Usage: next -- shows what you need to do next from the current list next tuesday -- displays the item that's due next in "tuesday" @@ -208,16 +218,17 @@ def nextDue(clist=current): """ return "The next item can be really useful!" + def showHelp(topic=False): """ Displays the help docs for a specific command or just everything! - + topic -- the thing to find help for - + "topic" can be any command or the word "commands". - + If thing is absent, displays the general help message (helpDoc) - + Usage: help -- displays general help message help add -- displays documentation for 'add' @@ -227,7 +238,7 @@ def showHelp(topic=False): if not topic: return helpDoc elif topic == "commands": - return commHelp + return commHelp elif topic in commands: return "%s:%s" % (topic, commands[topic].__doc__) elif topic in commands.values(): @@ -235,37 +246,37 @@ def showHelp(topic=False): else: return "There's no help for you, if you want %s" % topic + commands = { -"add" : addItem, -"edit" : editItem, -"info" : getInfo, -"list" : listItems, -"load" : loadCheckList, -"new" : newCheckList, -"next" : nextDue, -"remove" : remove, -"clean" : clean, -"save" : saveCheckList, -"help" : showHelp + "add": addItem, + "edit": editItem, + "info": getInfo, + "list": listItems, + "load": loadCheckList, + "new": newCheckList, + "next": nextDue, + "remove": remove, + "clean": clean, + "save": saveCheckList, + "help": showHelp, } commList = commands.keys() -commList.sort() -#Splits the list in half: [1,2,3,4,5] ==> [1,2] [3,4,5] -a = commList[:len(commList)/2+1] -b = commList[len(commList)/2+1:] +# commList.sorted(commList) +# Splits the list in half: [1,2,3,4,5] ==> [1,2] [3,4,5] +a = commList[: len(commList) / 2 + 1] +b = commList[len(commList) / 2 + 1 :] if len(a) > len(b): b.append("") commList = [] for i in range(len(a)): commList.append(a[i]) commList.append(b[i]) -#Combine the list into 2 columns -#Found at: http://stackoverflow.com/a/171707 -#By gimel, modified by S.Lott +# Combine the list into 2 columns +# Found at: http://stackoverflow.com/a/171707 +# By gimel, modified by S.Lott cols = 2 -lines = ("\t".join(commList[i:i+cols]) - for i in xrange(0,len(commList),cols)) -commHelp = '\n'.join(lines) +lines = ("\t".join(commList[i : i + cols]) for i in xrange(0, len(commList), cols)) +commHelp = "\n".join(lines) commList.sort() -del a,b,cols,lines +del a, b, cols, lines diff --git a/driver.py b/driver.py index 0e5bac3..5e1a003 100644 --- a/driver.py +++ b/driver.py @@ -1,50 +1,57 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # driver.py -# +# # Copyright 2012 Teddy Sudol <> -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. -# -VERSION = '0.1' +# +VERSION = "0.1" import argparse -import commands -#Create the arg parser for command line argument parsing -parser = argparse.ArgumentParser(description="An interactive checklist" - ,epilog=("--new and --load are mutually exclusive."+ - "FILE may be either a filename, a filepath, or a list's name.")) -parser.add_argument('-v','--version', action="version" - ,version="%(prog)s " + str(VERSION)) +# import commands + +# Create the arg parser for command line argument parsing +parser = argparse.ArgumentParser( + description="An interactive checklist", + epilog=( + "--new and --load are mutually exclusive." + + "FILE may be either a filename, a filepath, or a list's name." + ), +) +parser.add_argument( + "-v", "--version", action="version", version="%(prog)s " + str(VERSION) +) megroup = parser.add_mutually_exclusive_group() -megroup.add_argument('-n','--new', action='store_true' - ,help='start with an empty checklist') -megroup.add_argument('-l','--load',help='start with the list in LIST' - ,metavar="LIST") - +megroup.add_argument( + "-n", "--new", action="store_true", help="start with an empty checklist" +) +megroup.add_argument("-l", "--load", help="start with the list in LIST", metavar="LIST") + + def doComm(c, args): - #we already know c is a valid command! + # we already know c is a valid command! if c == "new" and len(args) <= 1: return commands.newCheckList(*args) elif c == "load" and len(args) == 1: return commands.loadCheckList(args[0]) elif c == "save" and len(args) == 0: return commands.saveCheckList() - elif c == "add" and len(args) in range(1,4): #if 1 <= len(args) <= 3 + elif c == "add" and len(args) in range(1, 4): # if 1 <= len(args) <= 3 return commands.addItem(*args) elif c == "remove" and len(args) <= 2: return commands.remove(*args) @@ -60,13 +67,11 @@ def doComm(c, args): return commands.nextDue(*args) elif c == "help" and len(args) <= 1: return commands.showHelp(*args) - elif c == 'version': + elif c == "version": return "CheckList v%s" % VERSION else: - return (("Invalid syntax of command '%s'" % c) - + "\nwith args "+repr(args)) - - + return ("Invalid syntax of command '%s'" % c) + "\nwith args " + repr(args) + def main(): args = parser.parse_args() @@ -76,30 +81,30 @@ def main(): print("We'd say there's a new checklist, then run interpreter") else: print("No args - We'd start the interpreter right away!") - print "\nWelcome to the interactive checklist" - print "Enter commands at the interpreter below. 'help' for help!" + print("\nWelcome to the interactive checklist") + print("Enter commands at the interpreter below. 'help' for help!") done = False while not done: - s = raw_input("-> ") + s = input("-> ") s = s.split() if s == []: - print "Please enter a command, silly!" + print("Please enter a command, silly!") elif s[0] == "version": - print + print() elif s[0] == "exit": - print "Thank you for using this program!" + print("Thank you for using this program!") done = True elif s[0] in commands.commands: - #the first part should always be the command, so the - #rest of the list will be args for the functions that need - #them. The function needs to split up the args itself. - print doComm(s[0], s[1:]) + # the first part should always be the command, so the + # rest of the list will be args for the functions that need + # them. The function needs to split up the args itself. + print(doComm(s[0], s[1:])) elif s[0] in commands.commands.values(): - print "Please use the alias for '%s'" % s[0] + print("Please use the alias for '%s'" % s[0]) else: - print "%s is not a command!" % " ".join(s) + print("%s is not a command!" % " ".join(s)) return 0 -if __name__ == '__main__': - main() +if __name__ == "__main__": + main() diff --git a/test_commands.ipynb b/test_commands.ipynb new file mode 100644 index 0000000..ddd5faa --- /dev/null +++ b/test_commands.ipynb @@ -0,0 +1,715 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 347, + "id": "initial_id", + "metadata": { + "collapsed": true, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:55.393432Z", + "start_time": "2024-01-26T23:35:55.341590Z" + } + }, + "outputs": [], + "source": [ + "# test_commands.ipynb" + ] + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001B[31mERROR: Could not find a version that satisfies the requirement checkBuilder (from versions: none)\u001B[0m\u001B[31m\r\n", + "\u001B[0m\u001B[31mERROR: No matching distribution found for checkBuilder\u001B[0m\u001B[31m\r\n", + "\u001B[0m" + ] + } + ], + "source": [ + "!pip3 install checkBuilder" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:56.881363Z", + "start_time": "2024-01-26T23:35:55.398284Z" + } + }, + "id": "c3f646f72d169800", + "execution_count": 348 + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "import checkBuilder" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:56.893974Z", + "start_time": "2024-01-26T23:35:56.884740Z" + } + }, + "id": "5ddf1354c47f2742", + "execution_count": 349 + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "\"\"\"\n", + "The main engine of the checkList program.\n", + "\n", + "Some notes:\n", + "- Checklists are always referred by name (\"checklist\")\n", + "- Most functions operate on either the current list or a specified list\n", + "\"\"\"\n", + "\n", + "import checkBuilder\n", + "from os.path import exists\n", + "from datetime import date\n", + "\n", + "#Eliminates the magic string \"current\"!\n", + "current = \"current\"\n", + "helpDoc =\"\"\"\\\n", + "Checklist creates, displays, and controls lists of tasks.\n", + "It's used for things like To-do lists or instructions.\n", + "Commands:\n", + " new: create a new checklist\n", + " load: load a checklist\n", + " save: save current checklist\n", + " add: create a new item and add to a list\n", + " remove: remove item X from checklist\n", + " clean: removes old or finished items from a list\n", + " list: display a checklist's items\n", + " linfo: display information about a list\n", + " info X: display information about item X\n", + " edit X: edit the information of item X\n", + " next: display the item that is due soonest\n", + " exit: Exit from the program\n", + " help: Displays this help message\n", + " version: Displays the version number\n", + "\n", + "add, delete, list, info, edit, and next can be used on more\n", + "than just the current list. The 'X's refer to the index of \n", + "the item to be affected; lists are indexed from 1.\n", + "Ex:\n", + "info(1, \"tuesday\") would display the information of the \n", + "first item in the list called \"tuesday\". Lists can be\n", + "referred to by either filename or listname.\\\n", + "\n", + "PLEASE use help topics for further information. To see a help topic:\n", + "help \n", + "ex: \n", + "help help\n", + "help add\n", + "\"\"\"\n", + "curList = [] #the current check list\n", + "\n", + "\n", + "def newCheckList(name='NewList'):\n", + " \"\"\"\n", + " Returns a new, empty checklist.\n", + " Alias: new\n", + " \n", + " name -- the name of the new checklist. (Default: \"NewList\")\n", + " \n", + " Usage:\n", + " newCheckList \"tuesday\" -- creates list \"tuesday\"\n", + " new -- creates a new list called \"NewList\"\n", + " \"\"\"\n", + " return checkBuilder.checkList()\n", + "\n", + "\n", + "def loadCheckList(fp):\n", + " \"\"\"\n", + " Loads a checklist from a YAML file.\n", + " Alias: load\n", + " \n", + " fp -- the identifier of the file.\n", + " \n", + " fp can either be the filename (\"checklist.yaml\"), the path to\n", + " the file (\"Lists/checklist.yaml\"), or the name of the checklist\n", + " (\"checklist\"). Since the checklist files are named after the\n", + " checklist they hold, this is rather simple to implement.\n", + " \n", + " Usage:\n", + " load tuesday -- sets \"tuesday\" as current list\n", + " \"\"\"\n", + " if exists(fp):\n", + " print(\"Will now load file---filename or filepath!\")\n", + " else:\n", + " print(\"Now we would check for a checklist of the same name as file\")\n", + " return exists(fp)\n", + "\n", + "\n", + "def saveCheckList():\n", + " \"\"\"\n", + " Saves a checklist in a YAML file.\n", + " Alias: save\n", + " \n", + " The file will be named after checklist and stored in the local dir,\n", + " ~/.checklists. On Windows, it would be AppData/.../.checklists.\n", + " \n", + " Usage:\n", + " save -- saves the current list\n", + " \"\"\"\n", + " return \"It would be saved in the YAML format in a file nearby\"\n", + "\n", + "\n", + "def addItem(item, clist=current, idx=0):\n", + " \"\"\"\n", + " Adds a new task to a checklist.\n", + " Alias: add\n", + " \n", + " item -- the item to add, a CheckItem object.\n", + " clist -- the name of the checklist to add item to.\n", + " idx -- the index to add the item at.\n", + " \n", + " item is the only required argument. If clist is not provided,\n", + " it is assumed that the item should be appended to the current list. \n", + " Checklists are 1-indexed, so a 0 index indicates that it should be\n", + " appended to the list.\n", + " \n", + " Usage:\n", + " add newItem tuesday 5 -- adds the newItem to \"tuesday\" at index 5\n", + " \"\"\"\n", + " return \"Item appended!\"\n", + "\n", + "\n", + "def remove(idx=0, clist=current):\n", + " \"\"\"\n", + " Removes the item at index i from the given checklist.\n", + " \n", + " idx -- the index of the item to remove.\n", + " clist -- the list to remove the item from.\n", + " \n", + " If clist is absent, the current list is assumed. If idx is missing,\n", + " it's assumed that the first item is removed.\n", + " If idx = '*', the list is cleared.\n", + " if idx = 'list', the list itself is deleted.\n", + " \n", + " Usage:\n", + " remove -- removes the first item from current list\n", + " remove list tuesday -- deletes \"tuesday\"\n", + " \"\"\"\n", + " return \"Deletes items or a checklist!\"\n", + "\n", + "\n", + "def clean(target=\"*all\", clist=current):\n", + " \"\"\"\n", + " Removes overdue and completed items from a checklist.\n", + " \n", + " target -- what to clean up\n", + " clist -- the checklist to clean. Default: current\n", + " \n", + " Possible values for target:\n", + " - *all\n", + " - *old\n", + " - *fin\n", + " *fin removes all completed items.\n", + " *old removes all overdue items.\n", + " *all removes both completed and overdue items.\n", + " \n", + " Possible values for clist:\n", + " - a checklist identifier\n", + " - *all\n", + " *all will clean every checklist that this program manages.\n", + " \n", + " usage:\n", + " clean *all\n", + " clean *old tuesday --removes overdue items from the list 'tuesday'\n", + " \"\"\"\n", + "\n", + "\n", + "def listItems(clist=current):\n", + " \"\"\"\n", + " Displays the checklist in a well-formatted YAML list.\n", + " THIS FUNCTION IS NOT IMPLEMENTED.\n", + " - YAML List?\n", + " - display items?\n", + " - what do??\n", + " \"\"\"\n", + " return \"The well-formatted items would be displayed here\"\n", + "\n", + "\n", + "def getInfo(idx=0, clist=current):\n", + " \"\"\"\n", + " Displays information about a given item or list.\n", + " Alias: info\n", + " \n", + " idx -- the index of the item to investigate\n", + " clist -- the list that holds the item\n", + " \n", + " If idx = 'list' or 0, print information about the list.\n", + " \n", + " Usage:\n", + " info list -- prints information about current list\n", + " info list \"tuesday\" -- prints info about \"tuesday\"\n", + " info 1 -- prints info about the first item\n", + " \"\"\"\n", + " return \"The item information is selected by index\"\n", + "\n", + "\n", + "def editItem(idx):\n", + " \"\"\"\n", + " Edits the item at index i of the current list.\n", + " NOT IMPLEMENTED.\n", + " \"\"\"\n", + " return \"An interactive editing mode would start\"\n", + "\n", + "\n", + "def nextDue(clist=current):\n", + " \"\"\"\n", + " Displays the information of the item that is due soonest.\n", + " Alias: next\n", + " \n", + " clist -- the list to check for items. Default: \"current\"\n", + " \n", + " If clist = \"*all\", every list is checked to find the item due\n", + " soonest.\n", + " Finds the item is due nearest to datetime.date.today.\n", + " \n", + " Usage:\n", + " next -- shows what you need to do next from the current list\n", + " next tuesday -- displays the item that's due next in \"tuesday\"\n", + " next *all -- displays the very next item that's due from all lists\n", + " \"\"\"\n", + " return \"The next item can be really useful!\"\n", + "\n", + "\n", + "def showHelp(topic=False):\n", + " \"\"\"\n", + " Displays the help docs for a specific command or just everything!\n", + " \n", + " topic -- the thing to find help for\n", + " \n", + " \"topic\" can be any command or the word \"commands\".\n", + " \n", + " If thing is absent, displays the general help message (helpDoc)\n", + " \n", + " Usage:\n", + " help -- displays general help message\n", + " help add -- displays documentation for 'add'\n", + " help help -- displays this message!\n", + " help commands -- displays the list of commands you can find help for\n", + " \"\"\"\n", + " if not topic:\n", + " return helpDoc\n", + " elif topic == \"commands\":\n", + " return commHelp\n", + " elif topic in commands:\n", + " return \"%s:%s\" % (topic, commands[topic].__doc__)\n", + " elif topic in commands.values():\n", + " return \"Please use the alias for %s to see help\" % topic\n", + " else:\n", + " return \"There's no help for you, if you want %s\" % topic\n", + "\n", + "commands = {\n", + " \"add\" : addItem,\n", + " \"edit\" : editItem,\n", + " \"info\" : getInfo,\n", + " \"list\" : listItems,\n", + " \"load\" : loadCheckList,\n", + " \"new\" : newCheckList,\n", + " \"next\" : nextDue,\n", + " \"remove\" : remove,\n", + " \"clean\" : clean,\n", + " \"save\" : saveCheckList,\n", + " \"help\" : showHelp\n", + "}\n", + "\n", + "\n", + "commList = sorted(commands.keys())\n" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:56.933258Z", + "start_time": "2024-01-26T23:35:56.902549Z" + } + }, + "id": "6a623428372f6bac", + "execution_count": 350 + }, + { + "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": "dict_keys(['add', 'edit', 'info', 'list', 'load', 'new', 'next', 'remove', 'clean', 'save', 'help'])" + }, + "execution_count": 351, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "commList = commands.keys()\n", + "commList" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:56.950840Z", + "start_time": "2024-01-26T23:35:56.928187Z" + } + }, + "id": "649cb7a8b21bb691", + "execution_count": 351 + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['add', 'edit', 'info', 'list', 'load', 'new', 'next', 'remove', 'clean', 'save', 'help'])\n" + ] + } + ], + "source": [ + "d = commList = commands.keys()\n", + "print(d)# from ww w . j a v a 2 s.c o m\n" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:57.008155Z", + "start_time": "2024-01-26T23:35:56.944377Z" + } + }, + "id": "96b8c15709e51ada", + "execution_count": 352 + }, + { + "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": "dict_keys(['add', 'edit', 'info', 'list', 'load', 'new', 'next', 'remove', 'clean', 'save', 'help'])" + }, + "execution_count": 353, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "commList" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:57.009931Z", + "start_time": "2024-01-26T23:35:56.955862Z" + } + }, + "id": "63d4839e5ebaaaba", + "execution_count": 353 + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index Range: range(0, 11)\n" + ] + } + ], + "source": [ + "commList_keys = list(commList)\n", + "\n", + "# Get index range\n", + "index_range = range(len(commList_keys))\n", + "\n", + "print(\"Index Range:\", index_range)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:57.062490Z", + "start_time": "2024-01-26T23:35:56.972123Z" + } + }, + "id": "ddbf15e97b0810e3", + "execution_count": 354 + }, + { + "cell_type": "markdown", + "source": [ + "type(commList) \n", + "dict(commList)" + ], + "metadata": { + "collapsed": false + }, + "id": "e60479a1a006b45a" + }, + { + "cell_type": "markdown", + "source": [ + "first_two = dict(list(d.items())[:2])\n", + "first_two" + ], + "metadata": { + "collapsed": false + }, + "id": "34d5b5a69830059b" + }, + { + "cell_type": "markdown", + "source": [ + "commList2 = list(commList) # commands.keys\n", + "commList2 # commands.keys\n", + "d = commList2" + ], + "metadata": { + "collapsed": false + }, + "id": "d15392d713d8e495" + }, + { + "cell_type": "markdown", + "source": [ + "import itertools\n", + "\n", + "dict(itertools.islice(d.keys(), 2))" + ], + "metadata": { + "collapsed": false + }, + "id": "87746f159ec8c5ed" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "# D = dict(zip(range(1, len(commands)), range(1, len(commands))))" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:57.063891Z", + "start_time": "2024-01-26T23:35:56.981532Z" + } + }, + "id": "1e5ea8b8c4cec5e1", + "execution_count": 355 + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "d = commList.keys() # Or you can use sorted() on the keys \n", + "for k in sorted(Ks): print(k, D[k])" + ], + "metadata": { + "collapsed": false + }, + "id": "aecec754ba5ec856" + }, + { + "cell_type": "markdown", + "source": [ + "commList = sorted(commands.keys())\n", + "commList2 = commList.index()" + ], + "metadata": { + "collapsed": false + }, + "id": "fc50357e72e58d21" + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,add\n", + "1,edit\n", + "2,info\n", + "3,list\n", + "4,load\n", + "5,new\n", + "6,next\n", + "7,remove\n", + "8,clean\n", + "9,save\n", + "10,help\n" + ] + } + ], + "source": [ + "for index, value in enumerate(commList):\n", + " print(f\"{index},{value}\")" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:35:57.064931Z", + "start_time": "2024-01-26T23:35:56.988205Z" + } + }, + "id": "c65659ff3501955d", + "execution_count": 356 + }, + { + "cell_type": "code", + "outputs": [ + { + "ename": "TypeError", + "evalue": "slice indices must be integers or None or have an __index__ method", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[358], line 4\u001B[0m\n\u001B[1;32m 1\u001B[0m commList \u001B[38;5;241m=\u001B[39m \u001B[38;5;28msorted\u001B[39m(commands\u001B[38;5;241m.\u001B[39mkeys()) \n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# commList.sorted(commList)\u001B[39;00m\n\u001B[1;32m 3\u001B[0m \u001B[38;5;66;03m#Splits the list in half: [1,2,3,4,5] ==> [1,2] [3,4,5]\u001B[39;00m\n\u001B[0;32m----> 4\u001B[0m a \u001B[38;5;241m=\u001B[39m \u001B[43mcommList\u001B[49m\u001B[43m[\u001B[49m\u001B[43m:\u001B[49m\u001B[38;5;28;43mlen\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mcommList\u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m/\u001B[39;49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[38;5;241;43m+\u001B[39;49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m]\u001B[49m\n\u001B[1;32m 5\u001B[0m b \u001B[38;5;241m=\u001B[39m commList[\u001B[38;5;28mlen\u001B[39m(commList)\u001B[38;5;241m/\u001B[39m\u001B[38;5;241m2\u001B[39m\u001B[38;5;241m+\u001B[39m\u001B[38;5;241m1\u001B[39m:]\n", + "\u001B[0;31mTypeError\u001B[0m: slice indices must be integers or None or have an __index__ method" + ] + } + ], + "source": [ + "commList = sorted(commands.keys())\n", + "# commList.sorted(commList)\n", + "#Splits the list in half: [1,2,3,4,5] ==> [1,2] [3,4,5]\n" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:36:03.455414Z", + "start_time": "2024-01-26T23:36:03.433878Z" + } + }, + "id": "63ea9891464bf093", + "execution_count": 358 + }, + { + "cell_type": "code", + "outputs": [ + { + "ename": "TypeError", + "evalue": "slice indices must be integers or None or have an __index__ method", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[359], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m a \u001B[38;5;241m=\u001B[39m \u001B[43mcommList\u001B[49m\u001B[43m[\u001B[49m\u001B[43m:\u001B[49m\u001B[38;5;28;43mlen\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mcommList\u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m/\u001B[39;49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[38;5;241;43m+\u001B[39;49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m]\u001B[49m\n", + "\u001B[0;31mTypeError\u001B[0m: slice indices must be integers or None or have an __index__ method" + ] + } + ], + "source": [ + "a = commList[:len(commList)/2+1]\n" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-26T23:37:29.250989Z", + "start_time": "2024-01-26T23:37:29.204885Z" + } + }, + "id": "e8c45b9edf4d1c8f", + "execution_count": 359 + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "b = commList[len(commList)/2+1:]" + ], + "metadata": { + "collapsed": false + }, + "id": "bd6129e2c2e543dd" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "if len(a) > len(b):\n", + " b.append(\"\")\n", + "commList = []\n" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "start_time": "2024-01-26T23:35:57.034155Z" + } + }, + "id": "96989163f8eb8335", + "execution_count": null + }, + { + "cell_type": "code", + "outputs": [], + "source": [], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "start_time": "2024-01-26T23:35:57.039933Z" + } + }, + "id": "aa1cf58ecc39a045", + "execution_count": null + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "\n", + "commList = []\n", + "for i in range(len(a)):\n", + " commList.append(a[i])\n", + " commList.append(b[i])\n", + "#Combine the list into 2 columns\n", + "#Found at: http://stackoverflow.com/a/171707\n", + "#By gimel, modified by S.Lott\n", + "cols = 2\n", + "lines = (\"\\t\".join(commList[i:i+cols])\n", + " for i in xrange(0,len(commList),cols))\n", + "commHelp = '\\n'.join(lines)\n", + "commList.sort()\n", + "del a,b,cols,lines" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "start_time": "2024-01-26T23:35:57.044174Z" + } + }, + "id": "208054299514c7c6", + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}