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 7731979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:36:59+00:00 2026-06-01T06:36:59+00:00

In Python EPD Traits I can keep variables that depend on others up to

  • 0

In Python EPD Traits I can keep variables that depend on others up to date either with a property or with actions in the method that takes care of changes of the ‘master’ variable.

I show here both ways, first with a Property:

from traits.api import HasTraits, Int, Property
class MyClass(HasTraits):
    val = Int
    dependent = Property(depends_on = 'val')

    def _get_dependent(self):
        return 4*self.val

and now with a trait handler:

from traits.api import HasTraits, Int
class MyClass(HasTraits):
    val = Int
    dependent = Int

    def _val_changed(self):
        self.dependent = 4*self.val

My question is, when should I use what? While researching this, I realized that one difference is that in the case of using a Property, the ‘dependent’ variable becomes read-only, if set up like here. But let’s say, the dependent is really dependent and I never have enough knowledge to set it directly, is there still a difference that I should be aware of?

Edit: This is similar to my other Traits related question, but not directly related.

  • 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-01T06:37:01+00:00Added an answer on June 1, 2026 at 6:37 am

    In this case I would definitely use a property, because dependent is in fact not holding any useful state you need to keep, you just need to access it.

    The second variant could also easily explode into your face in some cases. Imagine you have many more dependencies and you will need to add more in future. Every time you add a new member depending on val, you have to go to _val_changed and let you new member know. On the other hand, if you create you new member as a property reading val, it’s separate from the rest and you don’t mess you code more every time you add a dependency.

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

Sidebar

Related Questions

Python newbie here. I'm writing a script that can dump some output to either
Python's convention is that variables are created by first assignment, and trying to read
Python, C++, Scheme, and others all let you define functions that take a variable
Python (2.6.6 -- EPD 6.3-1 (32-bit)) can not find a binary executable when using
Python is so dynamic that it's not always clear what's going on in a
Python's getattr() method is useful when you don't know the name of a certain
python 2.6 reports that the md5 module is obsolete and hashlib should be used.
Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
python newbie here. I'm writing the code to control an experiment that has multiple
Python has the idea of metaclasses that, if I understand correctly, allow you to

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.