splitting common functions into a sepperate module

jonkersbart at gmail.com jonkersbart at gmail.com
Thu Mar 8 05:12:13 EST 2007


On 8 mrt, 10:36, Bruno Desthuilliers <bruno.
42.desthuilli... at wtf.websiteburo.oops.com> wrote:
> jonkersb... at gmail.com a écrit :
>
> > Dear,
>
> > I have wrote a script and want to group some functions of the script
> > in a separate modulo so that I can import the module in other scripts
> > and use the same functions there..
>
> > The problem is that the common functions need access to some global
> > variables defined in the script.
>
> And now you find out why globals are bad...
>
> > Python uses different namespaces for
> > different modules so I can't access the variables of the script in the
> > module.
>
> > What is the best solution to solve this problem?
>
> There's no one-size-fits-all answer. Usual solutions include:

I was hoping for a one-size-fits-all answer. But it seems to be that
it doesn't exists.
I already know these solutions, but was hoping for a better one.

> - passing the needed values as args to the functions
There are to many arguments so this is not a preferred solutions

> - wrapping the functions as methods of a class, passing the whole state
> as args to the class initializer.
I already considerate this one, but I don't like it because it is not
correct in terms of the object-oriented concept.
Because there are no other solutions I have to bury my bad feelings
and use this solution.

Thanks,
Bart





More information about the Python-list mailing list