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: Mon, 29 Feb 2016 18:11:33 +1100 Lines: 25 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 kPd6xkIHpbkrVETrpo0aeg0ZpU5oFV6orll4/2/DNC3A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; 'cc:addr :python-list': 0.09; 'effect.': 0.09; 'exception,': 0.09; 'imports': 0.09; 'subject:()': 0.09; 'python': 0.10; 'subject:not': 0.11; 'importing': 0.15; 'subsequent': 0.15; '"keep': 0.16; '.py': 0.16; '2016': 0.16; 'cc:name:python': 0.16; 'dropping': 0.16; 'end).': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'module,': 0.18; 'language': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'code.': 0.23; 'feb': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'script': 0.25; 'message-id:@mail.gmail.com': 0.27; 'module.': 0.27; 'code"': 0.29; 'really,': 0.29; 'restart': 0.29; 'run': 0.33; 'changed': 0.33; 'useful': 0.33; 'instead,': 0.33; 'loading': 0.33; 'raised': 0.33; '(for': 0.34; 'file': 0.34; 'running': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'execution': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'possible.': 0.36; 'received:209.85': 0.36; 'mode': 0.36; 'modules': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'times.': 0.38; 'received:209': 0.38; 'why': 0.39; 'rather': 0.39; 'more': 0.63; 'believe': 0.66; 'date,': 0.66; 'notices': 0.66; 'situation': 0.67; 'talking': 0.67; 'chrisa': 0.84; 'complexity': 0.84; "op's": 0.84; 'to:none': 0.91 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=g3g3uXsNvb7fY7871ekPcQ+x0W0QHnmMIdjGoIOHXuc=; b=dZYQxvYoQBEUOdPwLt3A0VFfCkHJ4Bd+i6/RsVGpzX1jjoj8jx8mPTlO7l5YoX5xUH iptMo+HNovXCLVw2GUR5AlZI0i7tisvOGH6fBYSFd9D7HuWizAp/yOfhwi6tP+oPbL/D 3ZJiJBBxeQ+E9/hb8M7zyo6moREKS+ccG+HI/An4QROoUyKcY+lkyopnnOatIRZeHvO/ SOVtZuN16cf6y8GeKvVzfsTm7gkjMpY+WnRCit2B3Js3mZMaMlREJGZYKYQCJqM4bMUb EAQTnkE8i4nys3RUmPV36Hc8Qkyq2YcmkkrCW6lnstKsuq2GttbK65OuZ+vIdrJehO1O 2oyw== 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=g3g3uXsNvb7fY7871ekPcQ+x0W0QHnmMIdjGoIOHXuc=; b=WWcts6Pq0uHxrfobQUIFyAtIja5ExKkzr3DoFZ9wukgpMm2KNobvPuOo8lAYUk/iBp dunAXMrNYhboX93vowH19Qmm6iN1DZT9QQce58CpIodFyK9B6SloP+pIQYxnF/s4RE/y FcT+fFUkFggDpEI0Q1P3ah0k8e7lsOQAZOTUy7uEtIQTbNWUulc8nPIIeu1eI6TUNZyP oOdXVk2B0V4CWuXJz1DxbE+C5ilTbrOeP4QC2ndeqAuZLWjWCIiS5dCpJ6YRiAvg4y+J zuqrW61SLq7HzNYqV/1urYRkQEudNptiiClURsDiFwNJjsqu2t6KrW0dw0RoVdn1YAhd Cmtg== X-Gm-Message-State: AD7BkJIWke/o8cynQLs7j/hvZp/nv6tmu7zBjRO5lXWrdS0k+5t9oJK1WMfvCtDPmAC+rOtYWjr6N+6mn7YAYA== X-Received: by 10.50.137.35 with SMTP id qf3mr8536669igb.92.1456729893956; Sun, 28 Feb 2016 23:11:33 -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:103689 On Mon, Feb 29, 2016 at 6:02 PM, Ian Kelly wrote: >> - if subsequent imports of same module in a session are not effective, why not simply flag those attempts as an error, rather than letting them go effect-less. > > Because there are legitimate reasons for importing the same module > multiple times. For example, I have a script that imports the sys > module. It also imports the os module, which imports the sys module. > Both the main module of my script and the os module have need of the > sys module, so they both import it. If subsequent imports of the > module raised an exception, this wouldn't be possible. 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. I would, instead, run a short-lived module and simply restart it after any edit (possibly dropping to interactive mode at the end). Save, restart. Save, restart. Python isn't optimized for the "keep running but change code" execution model (for that, use Pike, and pay the complexity overhead). ChrisA