On Feb 15, 4:04 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2007-02-15, placid <[EMAIL PROTECTED]> wrote: > > > > > Is it possible to be able to do the following in Python? > > > class Test: > > def __init__(self): > > pass > > > def puts(self, str): > > print str > > > def puts(self, str,str2): > > print str,str2 > > > if __name__ == "__main__": > > t = Test() > > t.puts("hi") > > t.puts("hi","hello") > > You tell us: what happened when you tried it?
Well, when i run it i get this error "puts() takes exactly 3 arguments (2 given)" which means that the second a time i try to define the puts() method "overwrites" the first one > > And then what happens when you do this? > > class Test: > def __init__(self): > pass > > def puts(self, *args): > print ' '.join(args) > > if __name__ == "__main__": > t = Test() > t.puts("hi") > t.puts("hi","hello") but this isn't overloading. > > Now an exercise for the gentle reader: change the puts method > so that this call works: > > t.puts("hi",1,3.45) > > -- > Grant Edwards grante Yow! Yow! I'm imagining > at a surfer van filled with > visi.com soy sauce! -- http://mail.python.org/mailman/listinfo/python-list