[Tutor] python classes and mysql

SA sarmstrong13@mac.com
Tue, 13 Aug 2002 10:23:48 -0500


On 8/13/02 8:40 AM, "rickp@telocity.com" <rickp@telocity.com> wrote:

> If I create multiple classes in python to deal with different aspects of
> a program and each of those classes needs to access mysql what is the
> best way of handling connections/cursors?
> 
> 1) Each class opens a connection and creates a cursor.
> 2) The toplevel opens a connection which is passed to the class which
>  then creates a cursor.
> 3) The toplevel opens a connection and creates a cursor which is passed
>  to the class.
How different?

>From my 'limited'OOP knowledge, classes should be a collection of similar
functions. So you would create an instance and then apply this instance to
some 'variable' (mind you I'm using a mathematical sense of the word
variable here), or rather the variable is passed to the instance of the
class and then worked upon by the class functions (attributes) and out pops
your desired result. Think of it as a big machine that your 'variable'
enters at one end and out pops your result at the other end and inside the
machine is a bunch of 'thingies' (hee, hee....) that manipulate the original
'variable' to produce the final result.


So now that I probably mucked that explanation up quite  a bit ...

The question you must ask yourself, are these classes truly different from
each other, or can some of these functions be combined into one class? So if
each class is truly different, can you trhow them all together in a module
and access them through that on module ( ie. Variable.Classes.class()) ?
This would probably fall under category 3). Yet if you combined all the
attributes under on class, you would still run the meat of your program at
the toplevel. So right away, I would think #1 is incorrect for both. So then
the debate comes down to #2 or #3. #2 seems to be more of the threaded
route, while #3 seems like there might be a bottleneck waiting for each
class to it's bit on the cursor before passing it off.  Therefore, I would
say that #2 would be the quickest of #2 and #3.

Just my $0.02 worth.
Good Luck.
SA


-- 
"I can do everything on my Mac I used to on my PC. Plus a lot more ..."
-Me