How to alter print behavior for an object in python -
i have unique class created , wish control output of flow..e.g:
obj = myobject() print obj
so instead of python does, want alter output. how do such thing?
change __str__
method
class myobject(object): def __str__(self): return 'foo' >>> print myobject() foo
Comments
Post a Comment