Replace 'write' method with '__str__'