Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: static variables Date: Wed, 2 Dec 2015 20:23:22 +1100 Lines: 16 Message-ID: References: <565cf163$0$1612$c3e8da3$5496439d@news.astraweb.com> <565e4329$0$1612$c3e8da3$5496439d@news.astraweb.com> <565e4861$0$1587$c3e8da3$5496439d@news.astraweb.com> <565EAA1D.501@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de CEXtcxRcCT4AbJwjk48t3gQ8Kd/gBzwvIkoqy8WjqGTg== Return-Path: 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; 'received:209.85.223': 0.03; 'static': 0.03; 'args': 0.04; 'attributes': 0.07; 'executable': 0.07; 'cc:addr:python-list': 0.09; 'python': 0.10; 'python.': 0.11; 'wed,': 0.15; 'argument': 0.15; 'declaration': 0.16; 'defaults,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'somewhere.': 0.16; 'statement.': 0.16; 'wrote:': 0.16; 'variable': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'otherwise,': 0.20; 'skip:" 30': 0.20; 'meant': 0.22; 'function,': 0.22; 'visible': 0.22; 'defined': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'initialized': 0.29; 'probably': 0.31; 'statement': 0.32; 'received:google.com': 0.35; 'instead': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'keyword': 0.36; 'totally': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209': 0.38; 'goes': 0.39; 'your': 0.60; 'body': 0.61; 'default': 0.61; 'more': 0.63; 'obvious': 0.76; 'chrisa': 0.84; 'pardon': 0.84; 'to:none': 0.91; 'have.': 0.93 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=uhOmTNqflB7JvdUNUPXm6GkC5Wx6nedxb4VDZV9a8sc=; b=ncZUEhtYw0gzWd8G2kZZ9+eQirbL+QQqQh/6X2QGxWbEPzXWgZPk3Sj3WYypL7YWWO Vyr/y28RxraAQshksS1dQvPKVoznDTXJDGAwHZfeHoV2ryw8DviiY8aZShEFqlvHBZuv pgyjXjH4PJHfXjM+87aFwavRkLDSwsHbgWIakiGUe3I4kNjLNfPSYDD+BARW962eYX5y 4CCvY+W7Ppe7Y3TI22eTFNAFWswDj2im0JJrper7KiWm8ThN79S+HNbPFLFWW2gM7b8G N3+GY52eoYr4t31K9q4Q4krVGtEmrPvvEoeaKv+4hBuaQ0Uf82vzMxRhWu2NoNnlH54C LK7A== X-Received: by 10.107.3.163 with SMTP id e35mr2446653ioi.157.1449048202235; Wed, 02 Dec 2015 01:23:22 -0800 (PST) In-Reply-To: <565EAA1D.501@rece.vub.ac.be> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99856 On Wed, Dec 2, 2015 at 7:21 PM, Antoon Pardon wrote: > I think python is unsuited for an obvious solution for static locals. > Because you need to initialise your static variable somewhere. If you > initialise whithin the body of your function, you will have a statement > that is essentialy a declaration instead of an executable statement. > Which goes totally against the dynamic nature op python. It ought to be initialized at the same time the function is defined - just like argument defaults, only without them being visible as arguments. If Python had a keyword that meant "currently-executing-function", that would work out well for attributes (and might also make recursion more optimizable); otherwise, default args are probably the cleanest way we have. ChrisA