I have very large settings for multiple applications and I want to print this as multi line string. Let me give example (simplified) and explain want I want to achieve and what I get. I think about use of some package to get such nice formatting.
I assume that constructors arguments are same to __dict__
or __slots__
- if not __dict__
or __slots__
is more important to show.
I wrote some formatting library for single line but maybe is better solution with multiline output and more options.
Update (important):
Please not suggest to customize __repr__ or __str__ - I can not or do not want to customize hundred of classes (especially from third party libraries).
class Endpoint:
def __init__(self, host_or_ip: str, port: int):
self.host_or_ip = host_or_ip
self.port = port
class ConnectionSettings:
def __init__(self, endpoints: list[Endpoint]):
self.endpoints = endpoints
class FarmSettings:
def __init__(self, name: str, connection_settings: ConnectionSettings):
self.name = name
self.connection_settings = connection_settings
def main():
settings = FarmSettings(
name='alfa',
connection_settings=ConnectionSettings(
endpoints=[
Endpoint('localhost', 80)
]
)
)
print(settings)
# what I get from default __repr__
#
# <__main__.FarmSettings object at 0x00000203EF713AF0>
#
# what do I want from some method
# FarmSettings(
# name='alfa',
# connection_settings=ConnectionSettings(
# endpoints=[
# Endpoint(name='localhost', port=80)
# ]
# )
# )
if __name__ == '__main__':
main()