Re: [Tutor] Class Inheritance

2017-02-21 Thread Peter Otten
Rafael Knuth wrote: > Hey there, > > I am trying to wrap my head around Class Inheritance in Python, and I > wrote a little program which is supposed to calculate revenues from > customers who don't get a discount (parent class) and those who get a > 30% discount (child class): > > class FullPri

Re: [Tutor] Class Inheritance

2017-02-21 Thread Alan Gauld via Tutor
On 21/02/17 09:49, Rafael Knuth wrote: > class DiscountCustomer(FullPriceCustomer): > discount = 0.7 > def calculate_discount(self, rate, hours): > print ("Your customer %s made you %s USD at a 30% discount > rate this year." % (self.customer, self.rate * rate * discount)) I meant

Re: [Tutor] Class Inheritance

2017-02-21 Thread Alan Gauld via Tutor
On 21/02/17 09:49, Rafael Knuth wrote: > class FullPriceCustomer(object): > def __init__(self, customer, rate, hours): > > > class DiscountCustomer(FullPriceCustomer): > discount = 0.7 > def calculate_discount(self, rate, hours): > > customer_one = DiscountCustomer("Customer A", 75,

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-24 Thread Alan Gauld
"Steven D'Aprano" wrote Yes, Tkinter could have had a ScrolledCanvas. It could have had lots of things, you have to draw the line somewhere otherwise you end up with one giant module that does *everything*: And for completeness there are a number of add-on modules in the standard library that

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-24 Thread Alan Gauld
"David Hutto" wrote In previous post I asked about turtle module importing from tkinter. But what I don't understand is why does Tkinter default it's casnvas to ScrolledCanvas in turtle.py, Tkinter doesn't. The author of the turtle module - which is not part of Tkinter but simply uses it -

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-23 Thread Steven D'Aprano
On Sat, 24 Apr 2010 03:41:04 pm David Hutto wrote: > In previous post I asked about turtle module importing from tkinter. > But what I don't understand is why does Tkinter default it's casnvas > to ScrolledCanvas in turtle.py, and then as a 'metaclass' for > ScrolledCanvas in turtle it calls TK.Fr

Re: [Tutor] Class Inheritance

2010-04-23 Thread Steven D'Aprano
On Sat, 24 Apr 2010 01:22:54 am David Hutto wrote: > I'm new, I touched the Holy lib, and > didn't check to reset the original Tkinter directory before posting. > Won't happen again. I'm sorry we got off on the wrong foot, you caught me at a time when I was frustrated about other things, and afte

Re: [Tutor] Class Inheritance

2010-04-23 Thread Steven D'Aprano
On Fri, 23 Apr 2010 04:54:11 pm David Hutto wrote: [...] > > Something is screwy there. I believe you have broken your > > installation by making changes to files without having any > > understanding of what you are doing. > > My original post was incorrect: the first error should be: > > C:\Users\

Re: [Tutor] Class Inheritance

2010-04-23 Thread Alan Gauld
"David Hutto" wrote While experimenting with Tkinter(python2.6), when from Tkinter import* is used I came across the following error: File "C:\Python26\lib\lib-tk\Tkinter.py", line 44, in from turtle import * Huh? Why is Tkinter.py importing from turtle? It doesn't in my Pyt

Re: [Tutor] Class Inheritance

2010-04-22 Thread Steven D'Aprano
On Fri, 23 Apr 2010 03:11:36 pm David Hutto wrote: > Hello List! > > While experimenting with Tkinter(python2.6), when from Tkinter > import* is used I came across the following error: > > C:\Users\ascent>c:\python26/Script3.py > Traceback (most recent call last): > File "C:\python26

Re: [Tutor] Class Inheritance

2007-09-14 Thread Eric Brunson
You're still using the wrong terminology... A "subclass" is "derived" (or "subclassed") from its "parent class" (or "super" class) A function that is part of the class definition (def func1(self): pass) is a "method" A variable that is part of the class definition or added after instantiation

Re: [Tutor] Class Inheritance

2007-09-13 Thread Eric Brunson
Lamonte Harris wrote: > Okay > > class A: >def __init__(self,x,y): > self.x = x > self.y = y > >def save(self,fn): > f = open(fn,"w") > f.write(str(self.x)+ '\n') > # convert to a string and add newline > f.write(str(self.y)+'\n') > return f # for

Re: [Tutor] Class Inheritance -> NameError

2005-11-30 Thread Tim Johnson
* John Fouhy <[EMAIL PROTECTED]> [051130 19:21]: <..snip...> > On 01/12/05, Tim Johnson <[EMAIL PROTECTED]> wrote: > superclass __init__ methods, or when you want to call them. So, it is > up to you to make that call. > > You can do that like this: > > class sub(test): > def __init__(self): >

Re: [Tutor] Class Inheritance -> NameError

2005-11-30 Thread John Fouhy
On 01/12/05, Tim Johnson <[EMAIL PROTECTED]> wrote: > My thanks to Christopher and Liam. I've revisited this > with the following: > class test: > def __init__(self): > self.s = ' there' > def val(self,V): > print '%s%s' % (V,self.s) > class sub(test): > def __init__(sel

Re: [Tutor] Class Inheritance -> NameError

2005-11-30 Thread Tim Johnson
My thanks to Christopher and Liam. I've revisited this with the following: class test: def __init__(self): self.s = ' there' def val(self,V): print '%s%s' % (V,self.s) class sub(test): def __init__(self): pass The following console session: >>> T = mylib.test() >

Re: [Tutor] Class Inheritance -> NameError

2005-11-30 Thread Liam Clarke-Hutchinson
Hi Tim, Either - class test: def __init__(self,v): self.__val = v def val(self): print self.__val class sub(test): def __init__(self, v): test.__init__(v) self.val() or - class sub(test): def __init__(self, v): test.__init__(v)

Re: [Tutor] Class Inheritance -> NameError

2005-11-30 Thread Christopher Arndt
Tim Johnson schrieb: > The following code snippet is meant to test inheritance: > class test: > def __init__(self,v): > self.__val = v > def val(self): > print self.__val > class sub(test): > def __init__(self): > val() > The following console session has an erro