Confused yet again: Very Newbie Question
mcl
mcl.office at googlemail.com
Mon Jul 7 13:39:42 EDT 2008
On Jul 7, 5:07 pm, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Mon, 7 Jul 2008 05:41:22 -0700 (PDT), mcl <mcl.off... at googlemail.com>
> declaimed the following in comp.lang.python:
>
> > My use of classes is because I want two classes one for global
> > variables and one for global functions.
>
> Which seems to violate the entire reason for using "classes" (and
> sounds like something that Java's syntax forces upon one). Classes (and
> instances of them) are typically defined to /combine/ the class/instance
> specific data and the functions that operate upon that data into a
> single object.
>
> If you just need a container for so-called "global" data, create a
> module. Same for utility functions.
>
> -=-=-=-=-=- myGlobalData.py
>
> something = 1
> else = 3
>
> -=-=-=-=-=- myUtilityFuncs.py
>
> def weird(a, b):
> return (a-b, b-a, a*b, a/b, float(a)/b)
>
> -=-=-=-=-=- main.py
>
> import myGlobalData
> import myUtilityFuncs
>
> results = myUtilityFuncs.weird(myGlobalData.something,
> myGlobalData.else)
> print results
> myGlobalData.something = results[2]
>
> > A function may set multiple global variable values, so what is the
> > best way to do this as 'return' only appears to be able to set one
> > value.
>
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr... at ix.netcom.com wulfr... at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-a... at bestiaria.com)
> HTTP://www.bestiaria.com/
Dennis,
Thank you for this reply. You are correct in what I was trying to do
and thank you for your very good example. I will now rewrite my code
changing classes to modules, which make more sense to me, even if it
is not proper Python.
I am much wiser about classes, but still a long way from fully
comprehending when and where to best use them.
Thank you all for your replies and links, as it solved my problems
enough, to get some code working.
Richard
More information about the Python-list
mailing list