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


Groups > comp.lang.python > #82240

Re: When do default parameters get their values set?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Duncan Booth <duncan.booth@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: When do default parameters get their values set?
Date 9 Dec 2014 21:18:03 GMT
Lines 23
Message-ID <XnsA3FED89759430duncanbooth@127.0.0.1> (permalink)
References <54866F2E.1765.complang@piz.noip.com> <54866F2E.1768.complang@piz.noip.com>
Reply-To duncan.booth@suttoncourtenay.org.uk
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Transfer-Encoding 8bit
X-Trace individual.net jcWJR95db+xR0SlVNCd+9QkOK5drt8LhLSVbDWjheuFT4Guhy7
Cancel-Lock sha1:tj64CN4Eqa7KRRsoYri3mxp0Q1Q=
User-Agent Xnews/2006.08.24 Hamster/2.1.0.11
X-Face .C;/v3#w@2k.C(.1v-}d=`|7AQ-%,#A$0ZGtAkLPvuawAM>3#D,pXaAb31%(=Gn2ZZK/Z~fd0y4't5iKK~F":}F2*|\mQYX+BUr4ZM*|+`@o-TKzFGwsJnan{)*b~QJ-Fu^u'$$nYV
Xref csiph.com comp.lang.python:82240

Show key headers only | View raw


"Dave Angel" <dave.angel@1:249/999.remove-cdt-this> wrote:

> On 12/08/2014 05:10 PM, 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.
>>
> 
> To answer the subject line, the default parameter(s) are evaluated
> when the function is compiled, and then stored with the function.

The function is compiled when the module is compiled. At latest that is 
when the module is imported (though in most cases it was probably compiled 
the first time you ran the code and isn't recompiled unless the source code 
changes).

The default parameters are actually evaluated when the 'def' statement is 
executed and the function object is created from the default arguments and 
the previously compiled code block.

-- 
Duncan Booth http://kupuguy.blogspot.com

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" <bsneddon@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
  Re: When do default parameters get their values set? "Chris Angelico" <chris.angelico@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
  Re: When do default parameters get their values set? "Dave Angel" <dave.angel@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
    Re: When do default parameters get their values set? Duncan Booth <duncan.booth@invalid.invalid> - 2014-12-09 21:18 +0000
      Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-09 18:07 -0500
        Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-09 18:44 -0800
          Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-10 13:38 -0500
            Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 18:18 -0800
              Re: When do default parameters get their values set? Chris Angelico <rosuav@gmail.com> - 2014-12-11 13:24 +1100
                Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 18:50 -0800
              Re: When do default parameters get their values set? Steven D'Aprano <steve@pearwood.info> - 2014-12-11 03:15 +0000
                Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 19:26 -0800
                Re: When do default parameters get their values set? Ben Finney <ben+python@benfinney.id.au> - 2014-12-11 14:49 +1100
                Re: When do default parameters get their values set? Chris Kaynor <ckaynor@zindagigames.com> - 2014-12-11 09:10 -0800
                Re: When do default parameters get their values set? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-12 09:51 +1100
              Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-11 15:44 -0500
  Re: When do default parameters get their values set? "Tim Chase" <tim.chase@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500

csiph-web