Creating Objects

Calishar calishar at *NOSPAM*home.com
Wed Jan 26 20:56:40 EST 2000


Hi folks,

  I'm working on solving a problem that my boss put to me the other
day, and I have run into a solution that I don't know how to implement
in Python (or any other language for that matter)

Basic description of problem (particulars not included)

Work out a system that can import information from (any number) of
systems, and write the infomration out (meaningfully) to any system in
the set.

I.e.
Assume a set a set of systems [A-G] the system needs to be able to
import from any of the seven systems, and write out it back out to any
of the seven. Ther may or may not be multiple instances of each system
type.


What I have in mind is defining a set of base classes and defining the
actual implementation at run-time

i.e.

# module my_classes.py
# imported as first part of main app

class system_a:
    def __init__(self):
	.....

class system_b:
    def __init__(self):
	.....
#(and so on)

and then during the main program what I would like to do is
...
    def do_translate(insystem, outsystem):
	class translateclass(system_dictionary[insystem],

system_dictionary[outsystem]):
    translateobject=translateclass(insystem, outsystem)
    translateobject.setsystems(input=insystem, output=outsystem)
    translateobject.translate()
....


Unfortunately I don't think run-time class definitions like this are
supported (understandably), but the more I think about it, the more I
am convinced that this is how to do what my boss wants.

  I would much rather do 8 class definitions (in this example) than
the 64 I would need to do otherwise.

  Am I pretty much looking at something that is un-doable, or am I
just looking at it wrong? (I think the latter because there seems to
be an idea floating just outside my brain range)

Calishar

P.s.  This would make my third project done fully within in Python (at
least for the RAD stage) Not bad considering my fist one started Jan
4th (yes, it was a Y2K patchup) 



More information about the Python-list mailing list