Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:55:48+00:00 2026-05-12T05:55:48+00:00

I’m trying to code a very rudimentary GTD app for myself, not only to

  • 0

I’m trying to code a very rudimentary GTD app for myself, not only to get organized, but to get better at coding and get better at Python. I’m having a bit of trouble with the classes however.

Here are the classes I have so far:

class Project:
    def __init__(self, name, actions=[]):
        self.name = name
        self.actions = actions
    def add(self, action):
        self.actions.append(action)

class Action:
    def __init__(self, do='', context=''):
        self.do = do
        self.context = context

Each project has actions to it, however I want to make it so that projects can also consist of other projects. Say daily I wanted to print out a list of everything. I’m having trouble coming up with how I would construct a list that looked like this

> Project A
>        Actions for Project A
>     Project B
>         Sub project A
>             Actions for Sub project A
>         Sub project B
>             Actions for Sub project B
>         Sub project C
>             Sub sub project A
>                 Actions for sub sub project A
>             Sub sub project B
>                 Actions for sub sub project B
>             Actions for Sub project C
>         Actions for Project B

It’s quite clear to me that recursion is going to be used. I’m struggling with whether to create another class called SubProject and subclass Project to it. Something there just makes my brain raise an exception.

I have been able to take projects and add them to the actions attribute in the Project class, however then I run into where MegaProject.actions.action.actions.action situations start popping up.

If anyone could help out with the class structures, it would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:55:49+00:00Added an answer on May 12, 2026 at 5:55 am

    You could create a subprojects member, similar to your actions list, and assign projects to it in a similar way. No subclassing of Project is necessary.

    class Project:
        def __init__(self, name, actions=[], subprojects=[]):
            self.name = name
            self.actions = actions
            self.subprojects = subprojects
    
        def add(self, action):
            self.actions.append(action)
    
        def add_project(self, project)
            self.subprojects.append(project)
    

    Even better, you may want to implement a composite pattern, where 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 c in self.children:
                c.mark_done()
    
    class Action:
        def __init__(self, do):
            self.do = do
            self.done = False
    
        def mark_done(self):
            self.done = True
    

    They key here is that the projects have the same interface as the actions (with the exception of the add/delete methods). This allows to to call methods on entire tree recursively. If you had a complex nested structure, you can call a method on the top level, and have it filter down to the bottom.

    If you’d like a method to get a flat list of all leaf nodes in the tree (Actions) you can implement a method like this in the Project class.

    def get_action_list(self):
        actions = []
        for c in self.children:
            if c.__class__ == self.__class__:
                actions += c.get_action_list()
            else:
                actions.append(c)
        return actions
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 282k
  • Answers 282k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer afpfs-ng is probably the closest thing to a usable AFP… May 13, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer Hard to figure out from descriptions. If you make a… May 13, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer the post here on the gettext function has some information… May 13, 2026 at 4:05 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.