Help creating new module which inherits existing class from another module.
ben+python at benfinney.id.au
Tue Feb 18 21:47:52 CET 2014
Jonno <jonnojohnson at gmail.com> writes:
> I'm not sure if this list is a suitable place to ask for this kind of
> help so if it's not please just suggest another forum which might be
> more suitable.
Welcome! Asking for help with writing Python code is definitely suitable
> I'm looking for help/suggestions how to architect a module (perhaps
> just a class).
Right, I don't see anything in your request that indicates why a new
module would be needed.
> There is an existing module I want to use which has a class we'll call
> *Existing Class*.
> I want to create a python module which allows me to create
This is all rather abstract. Can you explain what the existing class is
for? What the new class is for?
> with the following properties:
> - The new_objects have all the attributes of the Existing_Class (simply
> create a class that inherits from Existing_Class)
The syntax for that is::
where “Foo” is the existing class, “Bar” is the class you're defining.
It's not strictly true to say that Bar will thereby “have all the
attributes of” the existing class. Rather, the resolution chain will
mean that accessing attributes on Bar will fall-back to looking at Foo
for attributes not found in Bar.
> - I then want to create a nested structure under the new_objects
> something like:
Again, it's not clear why you're doing this. What are these attributes for?
> Where foo, bar, baz have the following properties:
> - All have *docstrings*
Docstrings are only for code objects: modules, classes, functions. Will
each of those attributes be one of those?
> - All are available for *tab completion* tools upon new_object creation.
Tab completion is up to the interactive tool you're using. Which tool is that?
> Some of which will have *new methods* which act in the following way:
> - new_object.foo.bar()
> - new_object.existing_method("foo.bar", *args)
This would be an unusual semantic. Why not call the existing method?
> Any pointers would be greatly appreciated.
I am smelling the likelihood that you have a strange design that needs
to be examined and changed. Can you describe what your purpose is that
you think needs this strange architecture?
\ “Anyone can do any amount of work provided it isn't the work he |
`\ is supposed to be doing at the moment.” —Robert Benchley |
More information about the Python-list