On Jun 13, 10:04 pm, Josiah Carlson <[EMAIL PROTECTED]>
wrote:
> Gabriel Genellina wrote:
> > En Wed, 13 Jun 2007 23:11:22 -0300, nik <[EMAIL PROTECTED]> escribió:
> >> It would seem that I want to actually save the source code for the
> >> class. I know that I could of course open up an editor and just make
> >> it, but my ideal would be to have the base class, Map, be able to make
> >> the sub-classes. I don't want the class definition. What I want is an
> >> actual class that I could later import and use somewhere else. I am
> >> planning to have each one of these map objects contain a different
> >> dictionary and then be able to import the map into the application,
> >> but have certain methods defined in the Map super-class to draw data
> >> out of the specific map's specific dictionary. I hope that makes
> >> sense.
>
> >> Something like,
> >> class Map:
> >> dict = {}
> >> def DoSomething(self):
> >> pass
>
> >> def MakeNewMapSubClass(self, newclassname):
> >> """ make a new file, newclassname.py that contains a new
> >> class
> >> newclassname(Map) that inherits from base-class Map.
>
> > And are you sure you actually need different subclasses? Will you
> > construct them several instances of each subclass? From the above
> > description I feel you want just different Map *instances*, each with
> > its own dict, not different *subclasses*.
>
> What you said, and that his solution sounds like a Java approach to the
> problem (subclass an abstract base class that calls specific methods on
> the subclass to "do the right thing").
>
> To offer the OP source he can use...
>
> class Map:
> def __init__(self):
> self.dict = {}
> def DoSomething(self):
> #do something with self.dict
>
> Every instance gets a new dictionary. Now, if he actually wants to
> change the behavior of the DoSomething method, of course then it would
> make sense to subclass Map.
>
> - Josiah
I am hoping to change the self.dict for each subclass. I realize that
I could save self.dict to file and then load in different dicts each
time I get a new instance of class. But I want to be able to make
subclasses of map that each have different self.dict. Then when I need
to use them, just import the module and use the specific dict, instead
of having to keep track of a separate dictionary file. I am new to
this, but I thought that this would be a regular thing to do in
python, because people must make classes in the interactive console
and then export them somehow for later use.
Thank you for your responses.
--
http://mail.python.org/mailman/listinfo/python-list