class implementation
Cameron Simpson
cs at zip.com.au
Tue Oct 8 19:55:28 EDT 2013
On 08Oct2013 01:20, markotaht at gmail.com <markotaht at gmail.com> wrote:
> I cant just subclassing doesent work. It seem the init method of the source class also calls out another class. And the problem is, i can subclass the other class to with the required function but the end result is that it doesent work, since the source class cant accsess the subclass functions.
>
> The source code is pykkar.
>
> https://courses.cs.ut.ee/all/MTAT.03.100/2012_fall/uploads/opik/_downloads/pykkar.py
>
> I want to add it a new ability called left(). I cant manipulate the source class, cause then my comp will be the only one where the program runs.
>
> class pykkar_l(Pykkar):
> def left(self):
> self._world.execute("left")
[...]
You normally need to call the superclasses' __init__ method as well.
Example:
def __init__(self):
Pykkar.__init__(self)
... any of your own init stuff ...
Likewise for your world_l class.
BTW, it is conventional to start class names with an upper case letters. Just
style, but it helps other people when reading your code.
Cheers,
--
Cameron Simpson <cs at zip.com.au>
It looks like you've got Mister Bus Error installed. - tjc
More information about the Python-list
mailing list