我有以下 python 类正在工作,我想创建一个命令行界面供用户使用。我遇到了 docopt 并认为使用它是一个好主意。我还没有遇到过展示如何将 docopt 集成到你的 python 类的教程或文档,我得到的只是小函数。可能吗?带有有用信息的链接会帮助我,或者只是一个小片段来帮助我解决问题,这将非常有帮助。
class Bootcamp(object):
tasks = {1: "TDD", 2: "OOP", 3: "Programming Logic", 4:
"Version Control", 5: "Agile Methodology",
6: "Growth Mindset", 7: "Asking Questions", 8:
"Motivation and Commitment", 9: "Speaking"}
def __init__(self, name, tasks=tasks):
self.name = name
self.tasks = tasks
self.completed = []
self.incompleted = tasks.values()
def add_completed_items(self, i):
if i in self.tasks.keys():
self.completed.append(self.tasks[i])
self.incompleted.remove(self.tasks[i])
return "tasks added to complete"
else:
return "not in the tasks"
def check_progress(self):
self.progress = float(len(self.completed)) / \
float(len(self.tasks)) * 100
return int(self.progress)