design - Python classes for simple GTD app -
I'm trying to code a very basic GTD app for myself not only to get organized but on coding Better to get better and better on Python though I'm having some difficulty with classes
Even I have classes:
class project: def __init __ (self, name, verb = []): self.name = name self.actions = verb deff addition (self, verb): self. Actions.append class action: def __init __ (self, do = '', context = ''): self.do = do self.context = context
in each project Action is taken for this, although I want to make it so that the projects can be of other projects. Say daily that I wanted to print a list of all I have to face about how I will build a list that will look like this
& gt; Project A & gt; Project A & gt; Actions for Project B & gt; Sub Project A & gt; Sub Project A & gt; Sub Project B & gt; Actions for Sub Project B & gt; Sub Project C & gt; Sub sub project A & gt; Sub sub project A & gt; Sub-Sub Project B & gt; Work for Sub-Sub Project B & gt; Work for Sub Projects C & gt; Activities for Project B
It is very clear to me that recycling is being used. I am struggling with it to make it another class, which is called sub-project and sub-class project. Something similar is that my brain enhances an exception.
I am able to take projects and add them to the work area in the project class, even then where mega project. Reactions.
You can create an all project member similar to your action list, and similarly assign projects can do. No sub-class of the project is necessary.
class project: def __init __ (self, name, verb = [], subproduct = []): self.name = name self.actions = actions self Subprojects = subprojects def joint , Verb): self.actions.append (verb) def add_project (self, project) self.subprojects.append (project)
Even better, you want to apply an overall pattern Where the projects are composites and actions are leaves.
class project: def __init __ (self, name, children = []): self.name = name self.children = children def add (self, object): self.children.append (Object) def mark_done (self): for self.children: c.mark_done () class action: def __init __ (self, do): self.do = Do self.done = wrong def mark_done (self): self The key here is that the projects have the same interface that works (with the exception of linking / removal methods) allows it to call the entire tree in a consistent way. If you have If there is a til nested structure, you can call a method at the top level, and filter it below. If you want a method to get a flat list of all the leaf nodes, in the tree (action) you can apply this type of method to the project class. C.children: if c .__ class__ = = self.__ class__: actions + = c.get_action_list () other: Actions.append (c) return action
Comments
Post a Comment