Jul-26-2023, 08:28 PM
(This post was last modified: Jul-26-2023, 08:28 PM by deanhystad.)
Why are you doing this?
Some vertical whitespace will make your program much easier to read. Two blank lines before a class or a function is suggested.
self.__angle_min = 0.0A single leading underscore is the convention for marking an attribute for internal use only (pseudo private). Leading with a doulbe underscore should be saved for the special case where subclasses of a class should not have access to the attribute. self.__angle_min = 0 creates an attribute with a mangled name _LaserProjection__angle_min. In the LaserProjection class, self.__angle_min will return this variable, but it will generate an error in a subclass.
class LaserProjection: def __init__(self): self.__angle_min = 0 def __str__(self): return f"Angles = {self.__angle_min}" class LaserProjectionSubclass(LaserProjection): def __init__(self): self.__angle_max = 0 def __str__(self): return f"Angles = {self.__angle_min}, {self.__angle_max}" print(LaserProjection()) print(LaserProjectionSubclass())
Error:Angles = 0
Traceback (most recent call last):
File "...test.py", line 18, in <module>
print(LaserProjectionSubclass())
File "...test.py", line 14, in __str__
return f"Angles = {self.__angle_min}, {self.__angle_max}"
AttributeError: 'LaserProjectionSubclass' object has no attribute '_LaserProjectionSubclass__angle_min'. Did you mean: '_LaserProjectionSubclass__angle_max'?
Why do you do this?import laser_geometry import laser_geometry.laser_geometry as lgIf you only use laser_geometry.laser_geometry, you do not need to also import laser_geometry.
Some vertical whitespace will make your program much easier to read. Two blank lines before a class or a function is suggested.