tagreader-python icon indicating copy to clipboard operation
tagreader-python copied to clipboard

Overload str in client class to give a pretty print

Open asmfstatoil opened this issue 4 years ago • 2 comments

I want to see name and type of data server that client is connected to when calling print(client). Will make it fast and easy to pass connection information to loggers...

asmfstatoil avatar Mar 15 '21 20:03 asmfstatoil

A pretty-printed string may not be the best option for something to pass along to other functions. How about something like this instead? client.status() {"name": "Servername", "imstype": "aspenone", "imsbasetype": "ip21"} (imsbasetype included since using Web API and ODBC should not matter)

You can format this however you want to your logger.

I suppose I could also define a str method that uses the same information but with no requirements on format.

einarsi avatar Apr 28 '21 07:04 einarsi

str is the informal string representation of an object (and repr the formal one), it is a nice feature alongside the listing you specified.

Primary use case for pretty print strings are debugging and logging for me.

asmfstatoil avatar May 06 '21 06:05 asmfstatoil