Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74441

initializing "parameters" class in Python only once?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!newsfeed.news.ucla.edu!news.jpl.nasa.gov!not-for-mail
From Catherine M Moroney <Catherine.M.Moroney@jpl.nasa.gov>
Newsgroups comp.lang.python
Subject initializing "parameters" class in Python only once?
Date Mon, 14 Jul 2014 15:32:13 -0700
Organization JPL Information Services, InterNetNews
Lines 30
Message-ID <53C45A6D.9040401@jpl.nasa.gov> (permalink)
NNTP-Posting-Host vila.jpl.nasa.gov
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.jpl.nasa.gov 1405377133 23666 137.78.73.60 (14 Jul 2014 22:32:13 GMT)
X-Complaints-To newsmaster@jpl.nasa.gov
NNTP-Posting-Date Mon, 14 Jul 2014 22:32:13 +0000 (UTC)
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.8; en-US; rv:1.9.2.14) Gecko/20110221 Thunderbird/3.1.8
Xref csiph.com comp.lang.python:74441

Show key headers only | View raw


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 
"Params.py" 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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

initializing "parameters" class in Python only once? Catherine M Moroney <Catherine.M.Moroney@jpl.nasa.gov> - 2014-07-14 15:32 -0700
  Re: initializing "parameters" class in Python only once? Chris Angelico <rosuav@gmail.com> - 2014-07-15 09:41 +1000
  Re: initializing "parameters" class in Python only once? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-15 01:05 +0100
  Re:initializing "parameters" class in Python only once? Dave Angel <davea@davea.name> - 2014-07-14 22:55 -0500

csiph-web