initializing "parameters" class in Python only once?

Mark Lawrence breamoreboy at
Tue Jul 15 02:05:32 CEST 2014

On 14/07/2014 23:32, Catherine M Moroney wrote:
> Hello,
> Pardon me for not using the proper Python language terms, but I hope
> that people can still understand the question:
> The problem:  I'm writing a large Python program and I have a bunch of
> parameters (whose values are static) that I want to make available to
> the rest of the code with minimum overhead and duplicate processing.
> I think that the simplest way would be to create a file called
> "" and then simply have statements like a = 1, b = 2, etc.
> in there (no classes, no methods, just a bunch of declarations).  But,
> some of these static parameters have to be calculated rather than simply
> hard-coded.
> I thought of creating a class called Params and having a bunch of
> methods (decorated with @classmethod) that set/calculate the value of
> all the parameters.  Easy enough, but then I have to create a Params
> object in every source file that uses these parameters, and that seems
> wasteful.
> The actual scope of the problem is very small, so memory/cpu time is not
> an issue.  I'm just looking for the most pythonic/elegant way of doing
> this.
> What is the recommended way of passing a bunch of static (hard-coded and
> calculated) parameters to various parts of the code?
> Thank you for any advice,
> Catherine

Besides the answers you've already had, you might like to consider using 
the enum module for some of your parameters.  IIRC it's only available 
in 3.4 but there's what I understand to be pretty much the same thing on 

My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

This email is free from viruses and malware because avast! Antivirus protection is active.

More information about the Python-list mailing list