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

  • SEARCH
  • Home
  • 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 8413875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:01:04+00:00 2026-06-10T01:01:04+00:00

First a general explanation, and then what I am actually working on: Let say

  • 0

First a general explanation, and then what I am actually working on: Let say you have a group of apples. Some properties could be shared, such as type = "Green Apple" and picked_date = "Aug 12 2012", but other data could be different between apples, such as is_bruised and weight or size. What is the most pythonic way to have editable values shared between apples such as type but also have individual attributes for each apple in the group? Coming from C, C++, my first instinct is a general struct, and a struct for each apple with a pointer to the general struct, as it seems silly for each apple instance to contain the group information, because if I wanted type = "Red Apple" I’d have to iterate though all the apples to edit their type value, which is a waste of programming power.

In real code, on my current work project, I am currently working on a git script to help parse output in a way that makes sense for my company. I have been reading up on (a) lists, (b) tuples, (c) dictionaries, and (d) classes in python, and I am really stuck trying to figure out the best way to represent this data.

To be specific, I am handling git commits, and there are two types of values I am concerned with: general properties shared between all commits, such as “do I print out the author of the commit?”, and specific properties such as “commit x has author y”. My current solution is inelegant:

class Commit(object):
    def __init__(self, author="", committer="", date="", issue="",
                 instruction="", message="", review="", sha="", short=""):
        self.author = author     
        self.committer = committer   
        self.date = date  
        self.instruction = instruction         
        self.issue = issue
        self.message = message
        self.review = review           
        self.sha = sha
        self.short = short

This class contains the data associated with a specific commit. Now, the data for all commits is stored as such:

 Attribute = namedtuple('Attribute', ['display', 'critical'])

 commit_attr = {'author': Attribute(display = True, critical = True),
                'committer': Attribute(display = True, critical = True),
                'date': Attribute(display = False, critical = False),
                'instruction': Attribute(display = True, critical = False),
                'issue': Attribute(display = True, critical = False),
                'message': Attribute(display = True, critical = False),
                'review': Attribute(display = True, critical = False),
                'sha': Attribute(display = True, critical = True),
                'short': Attribute(display = True, critical = True)}

Which is a dictionary with named tuples for the fields. “Critical” indicates if that field is required in a commit for it to be shown, display is used to determine if it should be printed or not.

Here’s my problem: I know that related data in python should be grouped in a coherent method, but I don’t know how to do that here: I could have a “pointer”, such as self.attr = commit_attr in the Commit() class, but this isn’t very clean and would depend on that object keeping its address, i.e. being mutable, otherwise if I changed the value of the general attributes it would no longer be associated with the Commit() class.

  • 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-06-10T01:01:05+00:00Added an answer on June 10, 2026 at 1:01 am

    I’m not entirely sure if this will be helpful to you, but Python has class attributes, which are shared between class instances:

    >>> class A(object):
    ...   foo = 'bar'  # Notice that this isn't in an __init__ function definition
    ... 
    >>> a = A()        # Just creating two distinct instances of A
    >>> b = A()
    >>> A.foo = 'baz'  # Now, I'm setting the class attribute
    >>> b.foo
    'baz'              # Notice how all instances of A changed
    >>> a.foo
    'baz'
    >>> 
    

    Editing the class attribute affects all instances at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could somebody provide a simple explanation of the JFreeChart axis-types? First, we have the
First, I acknowledge the possibility that this question could be a duplicate; just let
I'm working on my first real MVC application and I'm trying to follow general
First, let me say that I'm pretty new to Objective-C and iOS programming in
First to say that I'm new to MongoDb and document oriented db's in general.
I have a question about C# generics and delegate: First I describe the general
First of all, i'm using Jsf 1.2... I have a problem with submitting some
first take a look on this picture from localScope app : i have 2
first of all some details: I configured security as below in web.xml view plaincopy
First, some context: I'm a Python developer who has written a medium-sized application using

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.