Correct IDLE usage (was Reason for not allowing import twice but allowing reload())

Rustom Mody rustompmody at gmail.com
Wed Mar 2 23:17:40 EST 2016


On Thursday, March 3, 2016 at 9:38:11 AM UTC+5:30, Rustom Mody wrote:
> On Thursday, March 3, 2016 at 8:11:20 AM UTC+5:30, Terry Reedy wrote:
> > On 3/2/2016 10:22 AM, Rustom Mody wrote:
> > > On Tuesday, March 1, 2016 at 12:23:02 PM UTC+5:30, Terry Reedy wrote:
> > >> On 2/29/2016 7:42 AM, Rustom Mody wrote:
> > >>
> > >>> Is import needed at all when trying out in Idle?
> > >> ...
> > >>> So it does appear that
> > >>> 1. import not necessary with(in) idle
> > >>> 2. However import and f5 (ie is run as main) are different
> > >>>
> > >>> May some idle experts elaborate on this? Whats the idle idiom of import-ing?
> > >>
> > >> Rustom, since I know that you are not a rank beginner, I have trouble
> > >> understanding what you are asking.
> > >
> > > Heh!
> > > I know some things; dont know many things
> > >
> > >> F5 when editing foo.py is equivalent
> > >> to running "python -i foo.py" on a command line while 'in' the directory
> > >> containing foo.py.  In both cases, foo.py is run as a main module, with
> > >> __name__ == '__main__'.  The difference is that F5 runs foo.py under
> > >> IDLE supervision, with results going into and interactive inputs coming
> > >> from IDLE shell instead of the console interpreter.
> > >>
> > >> Imports are used in a module to access objects within the imported module.
> > >
> > > Let me try to explain again
> > >
> > > There is import and import.
> > > There is the formal meaning of the import keyword in python -- call it import-f
> > > There is the informal expectation and need of programmers to 'pull something
> > > into python' -- call it import-i
> > 
> > What do you mean by import-i that is different module import?  Keyboard 
> > input with input()? File input with file.read(), etcetera? Running a 
> > file with 'python filename' or 'python -m filename'?
> 
> I define something... either with
> def foo()...
> or
> x = ...
> 
> I want to see what foo does/what x is
> I want to check that my understanding of these matches python's representation
> of the same.
> I could keep typing the the
> def foo()...
> but that can get painful quickly
> 
> So I put these in a file...
> And import!
> 
> At this point I am pleased
> Because what I expect of import (import-i)
> and what python does with the import keyword (import-f) match... seemingly
> 
> Until I go and change the def in the file and run the import again
> Fails
> Restart python -- works

Just to be clear, I dont believe the problem is with import-f per se
It is with overloading python to be both scripting engine and interactive interpreter.

Both ruby and haskell find it expedient to separate the two
Ruby has irb and ruby
Haskell has ghc (compiler), runhaskell (scripting) ghci (interpreter)



More information about the Python-list mailing list