Results 1 to 2 of 2

Thread: multiple sub classes in python

  1. #1
    Join Date
    Jun 2010
    Beans
    380

    multiple sub classes in python

    I am learning python and in the example in book talks about multiple superclasses following is the example in book


    Code:
    class Calculator:
          def calculate(self,evaluate): 
                self.value=eval(expression)
    class Talker:    def talk(self): 
           print 'Hi, my value is ', self.value
    
    class TalkingCalculator(Calculator,Talker): 
          pass
    

    But when I type it in terminal

    Code:
    >>> class Calculator(object):
                    def calculate(self,evaluate):
                          self.value=eval(expression)
    >>> class Talker(object): 
                 def talk(self): 
                       print 'Hi, my value is ', self.value
    >>> class TalkingCalculator(Calculator, Talker):
                 pass
    
    I get following error
    Code:
    >>> TalkingCalcultor.__bases__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'TalkingCalcultor' is not defined

    Also the original formatting of my post is lost....how do I get it back here Ubuntu forums have seem to changed a lot...
    Last edited by jamesbon; June 3rd, 2013 at 05:03 PM.

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: multiple sub classes in python

    You'll kick yourself ... you missed an 'a'.
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •