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


Groups > comp.lang.python > #82154

Re: When do default parameters get their values set?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'run-time': 0.05; 'suppose': 0.07; 'variables': 0.07; 'here?': 0.09; 'subject:set': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'gui': 0.12; '"def"': 0.16; '-tkc': 0.16; 'argument.': 0.16; 'bind': 0.16; 'dictionary.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'function),': 0.16; 'imports': 0.16; 'subject:default': 0.16; 'subject:parameters': 0.16; 'subject:their': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'module': 0.19; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'prints': 0.31; 'skip:d 20': 0.34; 'but': 0.35; 'module.': 0.36; 'entry': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'changing': 0.37; 'wrong': 0.37; 'received:10': 0.37; 'issue': 0.38; 'rather': 0.38; 'skip:p 20': 0.39; 'expression': 0.60; 'completed': 0.61; 'back': 0.62; 'name': 0.63; 'happen': 0.63; 'to:addr:gmail.com': 0.65; 'default': 0.69; 'subject:get': 0.81; 'received:108': 0.93
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-MC-Relay Neutral
X-MailChannels-SenderId wwwh|x-authuser|tim@thechases.com
X-MailChannels-Auth-Id wwwh
X-MC-Loop-Signature 1418077449597:3025913012
X-MC-Ingress-Time 1418077449597
Date Mon, 8 Dec 2014 16:26:31 -0600
From Tim Chase <python.list@tim.thechases.com>
To bSneddon <w.g.sneddon@gmail.com>
Subject Re: When do default parameters get their values set?
In-Reply-To <8c10ecec-c057-4580-9711-94c0a5151646@googlegroups.com>
References <8c10ecec-c057-4580-9711-94c0a5151646@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AuthUser tim@thechases.com
Cc python-list@python.org
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.16741.1418078546.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418078546 news.xs4all.nl 2926 [2001:888:2000:d::a6]:34865
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82154

Show key headers only | View raw


On 2014-12-08 14:10, bSneddon wrote:
> I ran into an issue setting variables from a GUI module that
> imports a back end module.  My approach was wrong obviously but
> what is the best way to set values in a back end module.
> 
> #module name beTest.py
> 
> cfg = { 'def' : 'blue'}
> 
> def printDef(argT = cfg['def']):

At this point (after the "def" has completed defining the function),
the expression is evaluated and assigned to the default argument.

> beTest.cfg['def'] = "no red"
> beTest.printDef()
> 
> This prints blue.      I suppose because I am changing a local copy
> of cfg dictionary.  What is the write approach here?

Well, you can bind to a default dictionary rather than an entry in
that dictionary:


  cfg = {'def': 'blue'}
  def printDef(config=cfg):
    ...
    access(config['def'])

which will make the look-up happen at run-time rather than
definition/bind-time.

  beTest.cfg['def'] = 'Red!'
  beTest.printDef()
  # should print "Red!"

-tkc


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


Thread

When do default parameters get their values set? bSneddon <w.g.sneddon@gmail.com> - 2014-12-08 14:10 -0800
  Re: When do default parameters get their values set? Chris Angelico <rosuav@gmail.com> - 2014-12-09 09:28 +1100
  Re: When do default parameters get their values set? Chris Kaynor <ckaynor@zindagigames.com> - 2014-12-08 14:28 -0800
  Re: When do default parameters get their values set? Dave Angel <davea@davea.name> - 2014-12-08 17:30 -0500
  Re: When do default parameters get their values set? Tim Chase <python.list@tim.thechases.com> - 2014-12-08 16:26 -0600
  Re: When do default parameters get their values set? bSneddon <w.g.sneddon@gmail.com> - 2014-12-08 15:35 -0800
  Re: When do default parameters get their values set? Terry Reedy <tjreedy@udel.edu> - 2014-12-08 20:37 -0500

csiph-web