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


Groups > comp.lang.python > #74449

Re: initializing "parameters" class in Python only once?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'parameters': 0.04; 'static': 0.04; 'classes,': 0.05; 'subject:Python': 0.06; 'duplicate': 0.07; 'problem:': 0.07; 'processing.': 0.07; 'lawrence': 0.09; 'methods,': 0.09; 'params': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'terms,': 0.09; 'python': 0.11; 'language.': 0.14; 'advice,': 0.16; 'code?': 0.16; 'enum': 0.16; 'iirc': 0.16; 'parameters,': 0.16; 'pypi.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'passing': 0.19; 'small,': 0.19; 'seems': 0.21; 'issue.': 0.22; 'creating': 0.23; 'header :User-Agent:1': 0.23; '---': 0.24; 'source': 0.25; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'besides': 0.30; 'skip:@ 10': 0.30; "i'm": 0.30; 'code': 0.31; 'bunch': 0.31; 'calculated': 0.31; 'overhead': 0.31; 'parameters.': 0.31; 'question:': 0.31; 'file': 0.32; 'class': 0.32; 'this.': 0.32; 'actual': 0.34; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'minimum': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'easy': 0.60; 'most': 0.60; 'hope': 0.61; 'free': 0.61; 'viruses': 0.61; 'simply': 0.61; "you've": 0.63; 'protection': 0.63; 'our': 0.64; 'antivirus': 0.68; '3.4': 0.84; 'catherine': 0.84; 'pardon': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: initializing "parameters" class in Python only once?
Date Tue, 15 Jul 2014 01:05:32 +0100
References <53C45A6D.9040401@jpl.nasa.gov>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-92-24-213-134.ppp.as43234.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <53C45A6D.9040401@jpl.nasa.gov>
X-Antivirus avast! (VPS 140714-1, 14/07/2014), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11816.1405382722.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1405382722 news.xs4all.nl 2838 [2001:888:2000:d::a6]:44901
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74449

Show key headers only | View raw


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
> "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

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 
pypi.

-- 
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.
http://www.avast.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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