Can print() be reloaded for a user defined class?

Peng Yu pengyu.ut at gmail.com
Sat Sep 19 22:28:50 EDT 2009


Hi,

I have the following code. The last line does not print the members
("x" and "y") of 'my_bin'. I am wondering if there is a way to reload
the print function for bin, so that the last line print the members of
'my_bin'.

Regards,
Peng

class bin:
  def __init__(self, x, y) :
    self.x = x
    self.y = y

if __name__ == '__main__':

  my_bin = bin(1, 2)
  print my_bin



More information about the Python-list mailing list