Coding an extendable class

Tobias Pfeiffer me at privacy.net
Tue Dec 30 16:57:33 EST 2003


Hi!

I want to write a package of modules that deal with mathematical 
graphs. So my plan is to have a main.py file where the basic operations 
are done, like reading the file and creating an adjacence list and all 
that. In this main.py file, there is created a Graph class with several 
methods, such as deg(v) or delvertex(v).
And then, for all of the other things one can do with a graph, I want 
to code other modules, e.g. a file euler.py for finding an Euler way 
through the graph, that extends the class by the method eulerway(). I 
know that I can do something like

# graphtools/euler.py
import main
class Graph(main.Graph):
    	def eulerway(self):
    	[...]

and then the Graph class imported from euler.py will have both the old 
and the new methods. But what can I do if I want the end user to be 
able to combine several modules and I don't know in which order he will 
do? For example, by
  import graphtools.main, graphtools.hamilton
I can do the thingy described above, but what is with something like
  import graphtools.hamilton, graphtools.euler
? In that case I want the class to have all of the methods defined in 
the modules. How do I realize that in the best way?

Bye
Tobias

-- 
please send any mail to botedesschattens(at)web(dot)de




More information about the Python-list mailing list