Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82151
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| 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; 'value,': 0.04; 'argument': 0.05; 'defaults': 0.07; 'none:': 0.07; 'variables': 0.07; 'attributes': 0.09; 'function,': 0.09; 'meaningful': 0.09; 'subject:set': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'gui': 0.12; '"""print': 0.16; '*args': 0.16; 'defaults,': 0.16; 'fetch': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imports': 0.16; 'lazily': 0.16; 'sentinel': 0.16; 'subject:default': 0.16; 'subject:parameters': 0.16; 'subject:their': 0.16; 'subject:values': 0.16; 'unpack': 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; 'define': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'object,': 0.36; 'subject:?': 0.36; 'wrong': 0.37; 'being': 0.38; 'depends': 0.38; 'issue': 0.38; 'skip:p 20': 0.39; 'course.': 0.60; 'back': 0.62; 'name': 0.63; 'become': 0.64; 'subject:get': 0.81; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=xBnqkY1sbnHwX2P+WNWS5DfZjwTICItO56AgtbrH/F4=; b=DsR83PNXmSyRqSQxRbQ/kSPvNY2OQttm2YXA8eJ2l4RUFFVD562tPnW7XJTjkE4tT1 aA6ZFc+3oiwZf2RdB8HNKOS0Eta2zJ3akAtDaLJFdyJLH8mCQ6VEA1l6lkEv7GULgZTZ xsA9d3xPfeXzjoFBInuXEHpLxm5Evmj5XalF+l9mfz3aWWSckdO5x/0RYdz+RTQuj7MJ ZmwP9cZaRgLJE599SSExgXf4/AFHU6ixT9wUtqDU5y+G99F8fNqc7P9Sk9IxalyzxY12 Sq3Rp1sDSsf56eFDCDW5HhKiYz1oRL9zK8h6k5bNpo8nj4VWwm/VwIW+slP7VgQpB8BJ n/eg== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.38.133 with SMTP id c5mr27914946ice.26.1418077682584; Mon, 08 Dec 2014 14:28:02 -0800 (PST) |
| In-Reply-To | <8c10ecec-c057-4580-9711-94c0a5151646@googlegroups.com> |
| References | <8c10ecec-c057-4580-9711-94c0a5151646@googlegroups.com> |
| Date | Tue, 9 Dec 2014 09:28:02 +1100 |
| Subject | Re: When do default parameters get their values set? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.16738.1418077685.18130.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418077685 news.xs4all.nl 2970 [2001:888:2000:d::a6]:51415 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Body-CRC | 598813537 |
| X-Received-Bytes | 4431 |
| Xref | csiph.com comp.lang.python:82151 |
Show key headers only | View raw
On Tue, Dec 9, 2014 at 9:10 AM, bSneddon <w.g.sneddon@gmail.com> 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']):
> print argT
They're set when you define the function, and become attributes of the function.
If you want to lazily fetch the defaults, here's one common idiom:
def printDef(argT=None):
"""Print the argT value, defaults to cfg['def']"""
if argT is None: argT = cfg['def']
print(argT)
This depends on None not being a meaningful argument value, of course.
If you need to have any object at all able to be passed in, you'd need
to create a dedicated sentinel object, or use *args and unpack
yourself; but for a lot of cases, None works fine.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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