[Tutor] Re: Tutor digest, Vol 1 #2371 - 11 msgs

Nova Sano S. Surbakti Nova Sano S. Surbakti" <nano@intermatik.co.id
Wed Apr 16 02:03:01 2003

trpo> If I understand you right, you want to give the data to the other
trpo> objects, but you just don't want to touch MySQL again, is that right?

trpo> So say that we have you first class here

>>>> class Class_A:
trpo> ...     def getBigText(self):
trpo> ...         self.bigText = getThingsFromMySQL()

trpo> If you then add methods like this in your other classes:

>>>> class Class_B:
trpo> ...     def giveText(self, text):
trpo> ...             self.text = text

trpo> and the same for Class_C

trpo> You could to something like this in your main program:

trpo> a = Class_A()
trpo> b = Class_B()
trpo> c = Class_C()

trpo> a.getBigText()
trpo> b.giveText(a.bigText)
trpo> c.giveText(a.bigText)

trpo> now the objects b and c of Class_A and Class_B respectively will have an
trpo> own copy of the text extracted from MySQL. This text they will have in
trpo> their attribute text. So we have now that a.bigText == b.text == c.text.
trpo> Keep in mind that they now have different copies of the text, so if you
trpo> update the text the a object it will not get updated in the other
trpo> objects. As I understood it this was what you were after, but of course
trpo> I could be mistaken :)

trpo> Hope it helps!

trpo> Regards,
trpo> Kristoffer

Hi all,
Thanks Kristoffer for your advice.
Actually, those different classes are not executed at the same time.
So it will be called any time, depend on the request by the user.
In this case a user want to search for a certain thing from an
Inventory table, from a SearchForm. After that or at the same time
another user want to get another thing from same table.

What I think I want to do is:
Load data from table then keep it in memory. Each time the SearchForm
want to get the data, it don't have to touch MySQL again, but search
the data from memory?

What I'm doing right now is get the data from MySQL each time the
SearchForm executed, and it seems too slow.