Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'else:': 0.03; 'syntax': 0.04; 'elif': 0.05; 'subject:Python': 0.06; 'explicit': 0.07; 'suppose': 0.07; 'clause': 0.09; 'executes': 0.09; 'latter': 0.09; 'lost.': 0.09; 'read-only': 0.09; 'separately': 0.09; 'subject:into': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'mostly': 0.14; "wouldn't": 0.14; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'infinitely': 0.16; 'nesting': 0.16; 'rejected.': 0.16; 'scope,': 0.16; 'scopes': 0.16; 'statement.': 0.16; 'subject:variable': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'cc:addr:python.org': 0.22; 'convenient': 0.24; 'cc:2**0': 0.24; 'switch': 0.26; 'this:': 0.26; 'pass': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'idea,': 0.31; 'quite': 0.32; 'up.': 0.33; "i'd": 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'edge': 0.36; 'introducing': 0.36; 'method': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'two': 0.37; 'previous': 0.38; 'rather': 0.38; 'does': 0.39; 'extremely': 0.39; 'though,': 0.39; 'subject:Can': 0.60; 'most': 0.60; 'new': 0.61; 'entire': 0.61; 'such': 0.63; 'skip:n 10': 0.64; 'connecting': 0.64; 'more': 0.64; 'finally': 0.65; 'kept': 0.65; 'mar': 0.68; 'introduce': 0.78; "'from'": 0.84; "'with'": 0.84; 'connected:': 0.84; 'hard.': 0.84; 'is)': 0.84; "it'd": 0.84; 'presumably': 0.84; '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=n4niLoKb5zbunF7uvqSo2ZKoZPVAQfF4ipZ9gzYqgTE=; b=HfjPsLJVfXC+VZiBwZoVHbEs/2kIsyTtiInEiueXwOZCe8LQExAcl2kXeTNtWC9zNd GEPK/wLIZiXfpM6m9rW6fzHG9l2gkbvwmmao0AJwhvpw/4QBN3XnYOseiS5D0AysSMjV iVFjszj/Eldd+rhUoGxwmVP+UwZ2pa3r2xlG71Ox5kjVsNPSrrcuTHM3lace0jhZhsPH 6CBMUkbzlUQPfSJMgJkqCPpyi6MmGczdCkmKdU2u6cqzahwwMwFwko5lS8xzX8v75OJH WD+PRzepMcfq5aKR0UbiYeNjsD/6xaria/cIU5xpm7v8J8PFXzBp3PG1vU9KuAqREGfp hXlw== MIME-Version: 1.0 X-Received: by 10.68.247.6 with SMTP id ya6mr4197624pbc.45.1393602399434; Fri, 28 Feb 2014 07:46:39 -0800 (PST) In-Reply-To: <877g8fgsr1.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <877g8fgsr1.fsf@elektro.pacujo.net> Date: Sat, 1 Mar 2014 02:46:39 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393602403 news.xs4all.nl 2832 [2001:888:2000:d::a6]:59076 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67234 On Sat, Mar 1, 2014 at 2:29 AM, Marko Rauhamaa wrote: > BTW, here's a syntax that doesn't introduce any new keywords: > > with self.state from Connection.State: > if CONNECTING or CONNECTED: > ... > elif DISONNECTING: > ... > else: > ... Okay, I understand your 'from' now. What it really does is introduce a new scope, a read-only one presumably (because you really do NOT want the Pandora's Box that ECMAScript's 'with' is) from which unqualified names will be looked up. I would say that that's a very reasonable idea, quite separately from a switch statement. Suppose you had something like this: with scope(Connection.State): if self.state == CONNECTING: print("I am not",DISCONNECTING) It'd require a change to the LOAD_GLOBAL opcode to have it look in multiple scopes. If you want to change something, be explicit about where the change goes, but for lookups, it would be possible to have them go to multiple places. I suspect, though, that this wouldn't fly; I already posited such a theory, and was told that CPython's internals made it much more convenient to not introduce infinitely nesting scopes - the two use-cases that I'd most look at are these: # This executes as a function doubled = [x*2 for x in lst] # This implicitly unbinds e in a finally clause try: foo() except Exception as e: pass Neither is quite perfect; the closure method is mostly clean, but has some extremely esoteric edge cases, and the unbinding means that a previous value for 'e' is lost. But both are kept rather than introducing this concept of true subscoping, because CPython's implementation makes the latter hard. Predicating your entire proposal on something that has been avoided twice and just recently turned down, though, is a good way to get the whole proposal rejected. ChrisA