Python Forum
Class object instance. Link instance attribute to class. Can it be done easier.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class object instance. Link instance attribute to class. Can it be done easier.
#5
Windspar Wrote:Is there an easier or better way to tackle this ?
Why not use the point member as a private member and define x and y properties in MyObject?

class MyObject:
    @property
    def x(self):
        return self._point.x
    @x.setter
    def x(self, value):
        self._point.x = value
        self.update_point_total()
...
b.x = 5
c.y += 3
Reply


Messages In This Thread
RE: Class object instance. Link instance attribute to class. Can it be done easier. - by Gribouillis - Dec-03-2018, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [listbox] Feed it with dict passed to class? Winfried 3 157 5 hours ago
Last Post: Larz60+
  Class and methods Saida2024 2 150 7 hours ago
Last Post: deanhystad
  [split] Class and methods ebn852_pan 2 142 Yesterday, 08:07 AM
Last Post: Gribouillis
  How does this code create a class? Pedroski55 6 563 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  class definition and problem with a method HerrAyas 2 311 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Printing out incidence values for Class Object SquderDragon 3 342 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  class and runtime akbarza 4 446 Mar-16-2024, 01:32 PM
Last Post: deanhystad
  Operation result class SirDonkey 6 617 Feb-25-2024, 10:53 AM
Last Post: Gribouillis
  The function of double underscore back and front in a class function name? Pedroski55 9 792 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  super() and order of running method in class inheritance akbarza 7 838 Feb-04-2024, 09:35 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020