Re: A question about Python Classes

2011-04-23 Thread Steven D'Aprano
On Sat, 23 Apr 2011 13:30:02 -0700, chad wrote: > On Apr 22, 12:47 pm, Carl Banks wrote: >> On Thursday, April 21, 2011 11:00:08 AM UTC-7, MRAB wrote: >> > On 21/04/2011 18:12, Pascal J. Bourguignon wrote: >> > > chad  writes: >> >> > >> Let's say I have the following >> >> > >> class BaseHan

Re: A question about Python Classes

2011-04-23 Thread chad
On Apr 22, 12:47 pm, Carl Banks wrote: > On Thursday, April 21, 2011 11:00:08 AM UTC-7, MRAB wrote: > > On 21/04/2011 18:12, Pascal J. Bourguignon wrote: > > > chad  writes: > > > >> Let's say I have the following > > > >> class BaseHandler: > > >>      def foo(self): > > >>          print "He

Re: A question about Python Classes

2011-04-22 Thread Carl Banks
On Thursday, April 21, 2011 11:00:08 AM UTC-7, MRAB wrote: > On 21/04/2011 18:12, Pascal J. Bourguignon wrote: > > chad writes: > > > >> Let's say I have the following > >> > >> class BaseHandler: > >> def foo(self): > >> print "Hello" > >> > >> class HomeHandler(BaseHandler): >

Re: A question about Python Classes

2011-04-22 Thread Ian Kelly
On Fri, Apr 22, 2011 at 7:49 AM, Kyle T. Jones wrote: >> You don't need to create an instance of BaseHandler.  You have the >> class, Python knows you have the class -- Python will look there if the >> subclasses lack an attribute. >> >> ~Ethan~ >> > > Really?  That's not at all how I thought it w

Re: A question about Python Classes

2011-04-22 Thread Ethan Furman
Kyle T. Jones wrote: Ethan Furman wrote: chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I nev

Re: A question about Python Classes

2011-04-22 Thread Kyle T. Jones
Ethan Furman wrote: chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I never created an instance

Re: A question about Python Classes

2011-04-22 Thread Jean-Michel Pichavant
MRAB wrote: On 21/04/2011 18:12, Pascal J. Bourguignon wrote: chad writes: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHa

Re: A question about Python Classes

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 19:00:08 +0100, MRAB wrote: >>> How can HomeHandler call foo() when I never created an instance of >>> BaseHandler? >> >> But you created one! >> > No, he didn't, he created an instance of HomeHandler. > >> test is an instance of HomeHandler, which is a subclass of BaseHandler

Re: A question about Python Classes

2011-04-21 Thread Ethan Furman
chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I never created an instance of BaseHandler? Yo

Re: A question about Python Classes

2011-04-21 Thread MRAB
On 21/04/2011 18:12, Pascal J. Bourguignon wrote: chad writes: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call fo

Re: A question about Python Classes

2011-04-21 Thread Terry Reedy
On 4/21/2011 11:43 AM, chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I never created an ins

Re: A question about Python Classes

2011-04-21 Thread Pascal J. Bourguignon
chad writes: > Let's say I have the following > > class BaseHandler: > def foo(self): > print "Hello" > > class HomeHandler(BaseHandler): > pass > > > Then I do the following... > > test = HomeHandler() > test.foo() > > How can HomeHandler call foo() when I never created an in

Re: A question about Python Classes

2011-04-21 Thread Benjamin Kaplan
On Apr 21, 2011 12:55 PM, "chad" wrote: > > On Apr 21, 9:30 am, Jean-Michel Pichavant > wrote: > > chad wrote: > > > Let's say I have the following > > > > > class BaseHandler: > > > def foo(self): > > > print "Hello" > > > > > class HomeHandler(BaseHandler): > > > pass > > >

Re: A question about Python Classes

2011-04-21 Thread chad
On Apr 21, 9:30 am, Jean-Michel Pichavant wrote: > chad wrote: > > Let's say I have the following > > > class BaseHandler: > >     def foo(self): > >         print "Hello" > > > class HomeHandler(BaseHandler): > >     pass > > > Then I do the following... > > > test = HomeHandler() > > test.fo

Re: A question about Python Classes

2011-04-21 Thread Jean-Michel Pichavant
chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I never created an instance of BaseHandler? Cha

Re: A question about Python Classes

2011-04-21 Thread Rafael Durán Castañeda
You did: >>> class BaseHandler: ... def foo(self): ... print "Hello" ... >>> class HomerHandler(BaseHandler): ... pass ... >>> test = HomerHandler() >>> test.foo() Hello >>> isinstance(test, BaseHandler) True >>> isinstance(test, HomerHandler) True >>> You could say test is a