Super Class help

This is the place for queries that don't fit in any of the other categories.

Super Class help

Postby uven12 » Mon Nov 04, 2013 12:41 pm

Hello,

im new to python and i would like some help with super class. Im just doing a very simple little program to test. But i get a error i dont understand.

Super class:
Code: Select all
class chars:

    def __init__(self, name, health):
        self.name = name
        self.health = health
       


Class:
Code: Select all
from chars import chars

class warrior(chars):

    def __init__(self, name, health, ad, crit):
        chars.__init__(self, name, health)
        self.ad = ad
        self.crit = crit


and to call the warrior class i do
Code: Select all
char1 = warrior("Peter", 50, 20, 5)


<warrior.warrior instance at 0x02A97648> and thats the error i get :S
uven12
 
Posts: 1
Joined: Wed Oct 30, 2013 7:58 am

Re: Super Class help

Postby metulburr » Mon Nov 04, 2013 1:32 pm

<warrior.warrior instance at 0x02A97648> and thats the error i get :S

Thats not an error, its just displaying the objects location in memory.
this is an error:
Code: Select all
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero


What version of python are you using? I do not get the objects desc when in the interpreter in either python 2.7.4 or python 3.x? Or maybe it is just your IDE you are using.
Code: Select all
>>> obj = Sub()
>>>


Also if you are using python2.x, you must subclass from object to use new classes. However if you are using python3.x you do not have to subclass from object as it is already using the new classes. Plus its customary to capitalize class names.

EDIT:
oh yeah you can get it without assiging the object:
Code: Select all
>>> a = Test()
>>> Test()
<__main__.Test object at 0x7f5225698f10>
>>>
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1476
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Baldyr, Google [Bot] and 1 guest