Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Reason for not allowing import twice but allowing reload() Date: Tue, 1 Mar 2016 03:05:24 +1100 Lines: 32 Message-ID: References: <645cdd46-d4a4-49b3-a0d8-848608d70d73@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de zSZXhL0TR2PziWlZqq3Jrg8Nsw2YG5nLgnAb4ffKkjMg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'definition,': 0.09; 'effect.': 0.09; 'subject:()': 0.09; 'python': 0.10; 'python.': 0.11; 'subject:not': 0.11; 'importing': 0.15; '"exec"': 0.16; '"import"': 0.16; '.py': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'library"': 0.16; 'permits': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'gui': 0.18; 'language': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'work,': 0.21; 'latter': 0.22; 'am,': 0.23; 'code.': 0.23; '(where': 0.23; '(this': 0.24; 'header:In- Reply-To:1': 0.24; 'module': 0.25; "doesn't": 0.26; 'command': 0.26; 'rest': 0.26; 'connected': 0.27; 'message- id:@mail.gmail.com': 0.27; 'regular': 0.29; '(it': 0.29; 'really,': 0.29; 'restart': 0.29; 'code': 0.30; 'probably': 0.31; "can't": 0.32; 'changed': 0.33; 'useful': 0.33; 'loading': 0.33; 'tue,': 0.34; 'file': 0.34; 'running': 0.34; 'server': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'drop': 0.38; 'application': 0.39; 'rather': 0.39; 'clients': 0.61; 'more': 0.63; 'between': 0.65; 'mar': 0.65; 'believe': 0.66; 'date,': 0.66; 'notices': 0.66; 'situation': 0.67; 'talking': 0.67; 'chrisa': 0.84; "it'd": 0.84; "op's": 0.84; 'to:none': 0.91; 'technique': 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; bh=PILXXHirY9aV2b4CRNZSqrjJM1/muzltB0mZwlCkF7k=; b=hPvjm1yN/t/8mf+/o8sEFJVE3TLbTZ3OzvmYp/UQ59sjL0dvboVYFQdVv8QVMLZJiX PdKCqzYP2ZS16TTmH7fpGjjijJf8dLAOqffQ1zRFRYWmc+rT23KUMkjFwMQ8gvn1cp5D 4dv9vt1/FsNXm+PqeomZQ8O7JWB4f7SLpB6RfveLz5XvzzACE2/z+DBBMorCWL5pyEi7 zCfOZuuCabmbSUh1Nu5TQ3jV0EIHzoQEqONzfjQVHSWuoPb5f49fhHPGZFgDI/JUOntJ rwCehwuqAp1cPHlI98j66KhSJ80J63yduuABz24IAfS/weV9PvGotpWSuNRQx+1q9piu iqmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=PILXXHirY9aV2b4CRNZSqrjJM1/muzltB0mZwlCkF7k=; b=D/j0yEUjTU3cMAOs94VSHs1gWBk9usz0lrpsJvJNCdvjlzS5KNJ0Y2uWjKaCEaXS9h w4I7aPiWnNH+2Lgo1KoGFrz95jvqVO5Yexv5PXfaXAplEGsmBXYqJoPz6ZT/62+pA2wJ eI55648INGBsXe0LKZRc57KCd23P9/Mh1ogbh4yyv0+oY8r24QBZLfrsB7N7SOUO+GXk yd6noR/S9gauBwvcCu0SxhNwuykApk6SnjZfu9+FySuKEQXKsO/xJE7G7ToTU2EXR5Ha us38785XLyZl2fLmQwIYzB71QVP2w8Jr1lbuztkW2TvE+/hRsr8DKsOkjfVRm1rNnqEm BTfA== X-Gm-Message-State: AD7BkJIBa5HZjam13xiwETZBqvlcpDDo6Xz36G8j/jUdkHmJ5OzBuGMCEV3NX+7u643gTvqK5kTghmxbd/mLNQ== X-Received: by 10.50.28.105 with SMTP id a9mr11189266igh.94.1456761924169; Mon, 29 Feb 2016 08:05:24 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 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:103725 On Tue, Mar 1, 2016 at 2:33 AM, BartC wrote: >> I think the OP's talking more about the situation of having an active >> session (IDLE was mentioned), importing a local module (a .py file >> from the current directory), then editing the file and re-importing, >> which has no effect. While I am sympathetic to the problem, I don't >> believe the language should be changed here; what might be useful is >> something that notices that an already-loaded module is now out of >> date, but really, the best solution is a change of workflow that no >> longer has long-running modules loading live-updated code. > > > Not in Python (this was pre-Python actually) but I once used such a > technique all the time. > > The main set of modules would be running a GUI application which also had a > command line. I use this technique all the time, in current code. But not in Python. The main reason is to have a server that permits clients to connect and remain connected, and to update code in ways that affect those connected clients. So by definition, I can't restart the server (it would drop the connections), and the critical main loop doesn't reload, but all the rest of the code does. It's pretty much the same style you had. Doing the same thing in Python would probably best be done using "exec" rather than "import". It'd work, but you'd have to differentiate in code between "load this module which can be reloaded" and "import this module from the standard library" (where the latter would be the regular "import" statement). ChrisA