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


Groups > comp.lang.python > #103709

Reason for not allowing import twice but allowing reload()

X-Received by 10.141.0.9 with SMTP id b9mr13084661qhd.16.1456753912872; Mon, 29 Feb 2016 05:51:52 -0800 (PST)
X-Received by 10.50.138.165 with SMTP id qr5mr160365igb.10.1456753912840; Mon, 29 Feb 2016 05:51:52 -0800 (PST)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!w104no4111641qge.1!news-out.google.com!pn7ni5698igb.0!nntp.google.com!ok5no5359397igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Mon, 29 Feb 2016 05:51:52 -0800 (PST)
In-Reply-To <5c8e3283-2013-4f68-87b8-6311ccee64a3@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=117.215.21.23; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui
NNTP-Posting-Host 117.215.21.23
References <645cdd46-d4a4-49b3-a0d8-848608d70d73@googlegroups.com> <5c8e3283-2013-4f68-87b8-6311ccee64a3@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <ab6cc15d-ec34-4f9c-b1d2-9fb15787c262@googlegroups.com> (permalink)
Subject Reason for not allowing import twice but allowing reload()
From Rustom Mody <rustompmody@gmail.com>
Injection-Date Mon, 29 Feb 2016 13:51:52 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 2995
X-Received-Body-CRC 3852314546
Xref csiph.com comp.lang.python:103709

Show key headers only | View raw


On Monday, February 29, 2016 at 6:53:09 PM UTC+5:30, alien...@gmail.com wrote:
> Hello Rustom,
> 
> F5 in Idle restarts the Python interpreter (that's what my impression is). Whatever you have done earlier at Idle prompt (in Idle session) before F5 is gone after F5.
> 
> Try simple experiment at prompt.
> 
> >>> myvar="hello"
> >>> myvar
> 'hello'
> 
> myvar is gone after F5.
> 
> As for need of import in Idle session, I use it to
> - import sys
> - sys.append.path('D:\\Where\\Ever\\My\\Modules\\Lie')
> - import mymodule

Why does one use (something like) idle?
To experiment.

So what's your experiment-focus?
If it is mymodule then mymodule should be open in idle file window and idle will take care of paths

If its someothermodule.py that has an import of mymodule.py then
someothermodule should be handling the paths issue.

In neither case I see a reason to do it at idle prompt

[At least that's my understanding, hope an idle expert will weigh in on this]

In linux this question does not typically arise as one starts idle from the shell in the same directory as the python files one wants to play with

In windows... not sure of idiom...
Maybe right-click the idle icon and change its 'start-in' to the path where
your python files are situated?

My general impression (best-practices not semantics) is that changing sys.path
is allowed but hackish.
1. Modify sys.path
2. Using PYTHONPATH env variable
3. Use relative imports
4. Use packages
?. .pth files

is roughly decreasing in hackishness though unfortunately increasing in sophistication

http://stackoverflow.com/questions/19917492/how-to-use-pythonpath
http://stackoverflow.com/questions/18521503/pydev-how-to-avoid-adding-sub-directories-to-python-path-in-order-to-fix-unres

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