Help creating new module which inherits existing class from another module.

Jonno jonnojohnson at gmail.com
Wed Feb 19 10:56:22 EST 2014


On Tue, Feb 18, 2014 at 11:48 PM, Ben Finney <ben+python at benfinney.id.au>wrote:

> Jonno <jonnojohnson at gmail.com> writes:
>
> > I tried to explain the necessary properties in the requirements below.
>
> What you've described is a bunch of abstract behaviour.
>
> But as I said, I'm suspecting this is a poor design; and I can't know
> better until you explain what all this is *for*.
>
> What is the purpose of the code you're writing? What is special about it
> that makes you think it needs the specific properties you've described?
>
> I ask all this because I suspect there are better and/or simpler ways to
> achieve your *actual* goals. Maybe not; but to rule that out, I'd need
> to know more about the purpose.
>
>  Let me try to give an example then.
Let's say the existing module provides a class RoboCom() which allows the
user to communicate with robots (it doesn't). It handles all the
communication hooks to send commands to & receive updates from many kinds
of robots.

RoboCom has attributes like:
send_cmd()
receive_cmd()
as well as other attributes like robot_name etc which are created when an
instance of RoboCom is created. But a RoboCom object doesn't have any
attributes specific to the type of robot it will be communicating with.

Let's say the robots can be humanoid or canine.
A command that can be sent to the humanoid robot might look like:
1. send_cmd("left_leg.knee.raise 1.1")    # 1.1 being a height in units of m
A command that can be sent to the canine robot might look like:
2. send_cmd("tail.wag 3")     # where 3 = number of times to wag.

To be able to use RoboCom the user must currently look up the documentation
for the kind of robot they want to communicate with which is stored
somewhere in a text file and then enter it into the arguments of the
RoboCom methods which is a pain.

What I want to do is create a RoboCom-like object, specific to the type of
robot it will communicate with, which allows the user of that object to
discover which commands can & can't be sent to that type of robot.

The actual code executed to send the commands should be 1. & 2. above but
it would be more convenient to the user if they could type something like:
1A. humanoid_robocom1.left_leg.knee.raise.send(1.1)
2A. canine_robocom1.tail.wag.send(3)


Does that help explain things better?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140219/c7d58317/attachment.html>


More information about the Python-list mailing list