Python Forum
Trying to create a child class in Python 2.7
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to create a child class in Python 2.7
#1
I appreciate any help - Using Python 2.7 -->
Also, it's unclear to me how to format code on this site -

Error --->

Traceback (most recent call last):
File "/Users/meldejesus/Desktop/New_stuff/Code/newApps/Python_experiments/class.py", line 28, in <module>
cat1 = Cat("Fuzz")
TypeError: __init__() takes exactly 1 argument (2 given)

I appreciate any help - Using Python 2.7 -->
Also, it's unclear to me how to format code on this site -
class Dog(object):
def __init__(self, name):
self.name = name
self.age = 6
def age_update(self, age_update):
self.age+=age_update
print("new age: " + str(self.age))
def speak (self):
print("My name is "+ self.name + "and I'm "+ str(self.age))

class Cat(Dog):
#connects it to above
def __init__(self, lives):
# connects to what it will create
super(Cat, self).__init__(name)
self.lives=CatNature()


class CatNature():
def __init__(self, lives=9):
self.lives=lives


def show_lives(self):
print("This cat has " + str(self.lives) + " lives")


cat1 = Cat("Fuzz")
print ("Cat's name is " + cat1.name + " and " + str(cat1.age))

cat1.lives.show_lives()
Traceback (most recent call last):
File "/Users/meldejesus/Desktop/New_stuff/Code/newApps/Python_experiments/class.py", line 28, in <module>
cat1 = Cat("Fuzz")
TypeError: __init__() takes exactly 1 argument (2 given)
Reply


Messages In This Thread
Trying to create a child class in Python 2.7 - by mac77 - Sep-27-2017, 05:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 511 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
Question __init__ of Child Class zero_fX0 4 1,791 Mar-22-2023, 05:23 PM
Last Post: deanhystad
  Using one child class method in another child class garynewport 5 1,668 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Child class inheritance issue eakanathan 3 1,377 Apr-21-2022, 12:03 PM
Last Post: deanhystad
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,605 Jan-20-2022, 05:15 PM
Last Post: deanhystad
  Create Generator in the Class quest 1 2,150 Apr-15-2021, 03:30 PM
Last Post: jefsummers
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,036 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,071 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  How to create a varying qty of instances of a Class and name them? KM007 2 2,070 May-29-2020, 12:30 PM
Last Post: KM007
  calling on a method from one class into another class which is not a child NABA 5 2,877 Apr-29-2020, 07:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020