Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56383
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: class implementation |
| Date | 2013-10-08 10:31 +0000 |
| References | <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <99e763bd-9757-4d44-ad8d-10fd8a2dc3bd@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.847.1381228302.18130.python-list@python.org> (permalink) |
On 8/10/2013 04:20, markotaht@gmail.com wrote:
> I cant just subclassing doesent work.
I can't parse that "sentence."
> 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.
What's a "source class"? If you mean parent class, then say so.
Otherwise, if you give it a name, we might be able to follow. But
"source" and "other" don't narrow the field very much.
A parent class can certainly access the child class (subclass)
methods (not functions). But only if the instance (self) is an instance
of the child class. That's the whole point of subclassing.
>
> 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")
>
> def _cmd_left(self):
> headings = (N,E,S,W)
> cur_tile = self._get_current_tile()
>
> cur_heading_index = headings.index(cur_tile.pykkar_heading)
> new_heading_index = (cur_heading_index - 1) % 4
> cur_tile.pykkar_heading = headings[new_heading_index]
>
> self._update_pykkar_image(cur_tile)
>
> class world_l(World):
> def left(self):
> self._world.execute("left")
>
> These are my subclasses. For it to work. Class World, must obtain the method from subclass world_l
Then it sounds like you should make sure that the global value "world"
in that module is an instance of your world_l class, rather than an
instance or World. And that the proxy is an instance of pykkar_l rather
than of Pykkar.
import pykkar
layout = "fdlkjdsljdslfkjsdljfdsf"
pykkar.world = world_I(layout)
??? = pykkar_l(pykkar.world)
You don't show your own top-level code, so I can't integrate it in.
By the way, it's conventional to use uppercase for class names, and
lowercase for instances of those classes.
I'm astounded that your class is using eval and multiprocessing before
understanding classes and subclasses.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
class implementation markotaht@gmail.com - 2013-09-30 01:43 -0700
Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 11:03 +0200
Re: class implementation markotaht@gmail.com - 2013-09-30 02:10 -0700
Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 11:27 +0200
Re: class implementation markotaht@gmail.com - 2013-09-30 05:41 -0700
Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 15:02 +0200
Re: class implementation Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-30 09:21 -0400
Re: class implementation Piet van Oostrum <piet@vanoostrum.org> - 2013-09-30 13:32 -0400
Re: class implementation Dave Angel <davea@davea.name> - 2013-09-30 19:34 +0000
Re: class implementation 88888 Dihedral <dihedral88888@gmail.com> - 2013-10-01 00:01 -0700
Re: class implementation Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 17:28 -0400
Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-30 23:45 +0000
Re: class implementation Ethan Furman <ethan@stoneleaf.us> - 2013-09-30 17:31 -0700
Re: class implementation random832@fastmail.us - 2013-09-30 17:49 -0400
Python variables? [was Re: class implementation] Ethan Furman <ethan@stoneleaf.us> - 2013-09-30 15:02 -0700
Re: Python variables? Ben Finney <ben+python@benfinney.id.au> - 2013-10-01 08:37 +1000
Re: Python variables? [was Re: class implementation] Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 19:45 -0400
Re: Python variables? [was Re: class implementation] "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-10-01 01:29 +0100
Re: Python variables? Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 19:47 -0400
Re: Python variables? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 01:03 +0000
Re: Python variables? Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 21:28 -0400
Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 00:19 +0000
Re: class implementation markotaht@gmail.com - 2013-10-06 06:15 -0700
Re: class implementation Terry Reedy <tjreedy@udel.edu> - 2013-10-06 15:52 -0400
Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-07 01:24 +0000
Re: class implementation markotaht@gmail.com - 2013-10-08 01:20 -0700
Re: class implementation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-08 09:41 +0100
Re: class implementation Dave Angel <davea@davea.name> - 2013-10-08 10:31 +0000
Re: class implementation Cameron Simpson <cs@zip.com.au> - 2013-10-09 10:55 +1100
Re: class implementation markotaht@gmail.com - 2013-10-10 11:34 -0700
Re: class implementation Cameron Simpson <cs@zip.com.au> - 2013-10-11 09:07 +1100
Re: class implementation Piet van Oostrum <piet@vanoostrum.org> - 2013-10-10 19:29 -0400
Re: class implementation Ben Finney <ben+python@benfinney.id.au> - 2013-10-11 10:51 +1100
Re: class implementation markotaht@gmail.com - 2013-10-08 07:05 -0700
Re: class implementation "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-10-09 00:41 +0100
csiph-web