[Tutor] Format problem

Alan Gauld alan.gauld at yahoo.co.uk
Tue Oct 20 06:15:45 EDT 2020


On 20/10/2020 00:56, P L wrote:
> I'm not sure why the __str__(self) is not working as intended. 
> All my outputs are not at the nearest hundredth. 

You never call the __str__() method so how do you know it
is not working?

> import random
> 
> class Server:
>     def __init__(self):
>     def add_connection(self, connection_id):
>     def close_connection(self, connection_id):
>     def load(self):
>     def __str__(self):
> 
> server = Server()
> server.add_connection("192.168.1.1")
> print(server.load())

You print the result of load() you never print server.

To call __str__ you'd need a line like:

print(server)

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list