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


Groups > comp.lang.python > #103689

Re: Reason for not allowing import twice but allowing reload()

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
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 <mailman.10.1456729896.2321.python-list@python.org> (permalink)
References <645cdd46-d4a4-49b3-a0d8-848608d70d73@googlegroups.com> <CALwzidnouPmT26-VZsGpoqojM92yZzY5+DSLta5fCqop1YNoUg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de kPd6xkIHpbkrVETrpo0aeg0ZpU5oFV6orll4/2/DNC3A==
Return-Path <rosuav@gmail.com>
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 <CALwzidnouPmT26-VZsGpoqojM92yZzY5+DSLta5fCqop1YNoUg@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103689

Show key headers only | View raw


On Mon, Feb 29, 2016 at 6:02 PM, Ian Kelly <ian.g.kelly@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-28 22:40 -0800
  Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-02-29 18:01 +1100
    Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-01 22:18 +1100
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-01 22:39 +1100
        Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 04:11 +1100
          Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 05:04 +1100
      Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 14:53 -0700
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 09:02 +1100
      Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 15:29 -0700
        Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 12:19 +1100
          Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 19:22 -0700
            Re: Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-03-02 02:15 -0800
              Re: Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-03-02 02:19 -0800
            Re: Reason for not allowing import twice but allowing reload() Grant Edwards <invalid@invalid.invalid> - 2016-03-02 15:15 +0000
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 11:13 +1100
  Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-29 00:02 -0700
  Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-02-29 18:11 +1100
    Re: Reason for not allowing import twice but allowing reload() BartC <bc@freeuk.com> - 2016-02-29 15:33 +0000
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-01 03:05 +1100
  Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-02-29 04:42 -0800
    Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Terry Reedy <tjreedy@udel.edu> - 2016-03-01 01:52 -0500
      Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 07:22 -0800
        Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Terry Reedy <tjreedy@udel.edu> - 2016-03-02 21:40 -0500
          Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 20:07 -0800
            Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 20:17 -0800
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:00 -0800
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:22 -0800
    Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:25 -0800
      Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 04:00 +1100
        Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-05 04:51 -0800
          Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-10 00:53 +1100
    Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-02-29 05:51 -0800
      Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 07:13 -0800
    Re: Reason for not allowing import twice but allowing reload() Terry Reedy <tjreedy@udel.edu> - 2016-03-01 02:04 -0500
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-06 00:20 -0800
    Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-07 01:50 +1100
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-06 00:31 -0800

csiph-web