dominicprice / endplay

A suite of tools for generation and analysis of bridge deals. Read the documentation at https://endplay.readthedocs.io
MIT License
21 stars 5 forks source link

Implementing toString on classes #27

Open ThorvaldAagaard opened 11 months ago

ThorvaldAagaard commented 11 months ago

It would be nice if there was implemented a str function on the different classes.

Like this for a board

image

In some classes __str__ is implemented but returning PBN-format.

dominicprice commented 11 months ago

There is a pprint method on some classes too (Hand, Deal, DDTable) I think, which prints in a diagram format. In general, I prefer __str__ to semantically mean "create a string I can pass to other stuff" rather than "display the object", which is why I have opted for the two different method types (you can of course also pprint to a string by setting the stream to an io.StringIO, as well as spit it out to a file by passing the file object returned by open).

Auctions can also be printed, but I for some reason shoved it in endplay.utils.io.pprint_auction where presumably nobody will ever find it...

All that said: I think Board is a good candidate for a string representation like this though!

ThorvaldAagaard commented 11 months ago

Yes, it is always a tradeof between making objects passable to other stuff and the developers need for viewing the object, when debugging and coding :-)

One way of solving it could be to implement a serialize method on every object