Apr-11-2025, 07:41 PM
I think it makes a lot more sense to do this:
Now is a good time to start following python coding conventions. Class names start with an uppercase letter. This makes it easy to tell the difference between creatin an instance of a class and calling a function.
p is an odd thing. There are multiple ways that p can be handled. You could make p a class attribute.
You could make p an argument in the init method. If you want p to be 0.8 most of the time, you can set a default value.
class Frame: def __init__(self, width, height): p = 0.8 self.width = width self.height = height self.image = Image(self.width * p, self.height * p) class Image: def __init__(self, width, height): self.width = width self.height = heightHaving width as an argument to Image.__init__ and as an attribute, it is weird that the two values would not match immediately after an instance is created.
Now is a good time to start following python coding conventions. Class names start with an uppercase letter. This makes it easy to tell the difference between creatin an instance of a class and calling a function.
p is an odd thing. There are multiple ways that p can be handled. You could make p a class attribute.
class ImageFrame: PROPORTIONALITY = 0.8 def __init__(self, width, height): self.width = width self.height = height self.image = Image(self.width * self.PROPORTIONALITY, self.height * self.PROPORTIONALITY)An advantage with this is code can ask the ImageFrame (a better name than Frame for a Frame that's defining attribute is it contains an image) what is the value of the proportionality constant. It also makes the proportionality constant stand out. If you later decide that the images should be 90% as big as the frame, it is easy to find where proportionality is set.
You could make p an argument in the init method. If you want p to be 0.8 most of the time, you can set a default value.
class ImageFrame: def __init__(self, width, height, proportionality=0.8): self.width = width self.height = height self.image = Image(self.width * proportionality, self.height *proportionality)An advantage to this approach is you can make different image frames with different p values.