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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -