Python Forum
Accessing method attributes of python class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing method attributes of python class
#1
Hello,

I am pretty new to python and OOP, so please don't be too harsh on my question Smile
I have the following code:

class frame:
    def __init__(self, width, height):
        self.frame_width = width
        self.frame_height = height

    def image(self):
         self.width = 0.8 * self.frame_width
         self.height = 0.8 * self.frame_height

picture = frame(60,40)
My question is, how can I access the image width in the following manner:
picture.image.width
Reply


Messages In This Thread
Accessing method attributes of python class - by Abedin - Apr-11-2025, 04:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 1,419 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 2,347 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 1,838 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  Using one child class method in another child class garynewport 5 3,158 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Accessing same python script from multiple computers bigrockcrasher 1 2,899 May-25-2022, 08:35 PM
Last Post: Gribouillis
  Python modules for accessing the configuration of relevant paths Imago 1 2,383 May-07-2022, 07:28 PM
Last Post: Larz60+
  accessing value in dict_values class CompleteNewb 14 8,641 Mar-31-2022, 04:02 AM
Last Post: deanhystad
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,890 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  class, attribute and method Frankduc 9 3,989 Feb-27-2022, 09:07 PM
Last Post: deanhystad
  Distinguishing different types of class attributes Drone4four 4 3,860 Feb-21-2022, 06:34 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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