What's the difference between coding in the IDLE and the terminal? - python

I installed python 2.7 and I have the IDLE version of it. I also created two environments using the terminal of Python 3 and Python 2 with conda.
When I type python it shows me that I'm using Python 3.5.2. Now:
How can I switch between two versions in the IDLE or the terminal?
What's the difference between coding in the IDLE or the terminal?

You cannot switch versions of Python from within Python. IDLE runs on top of whatever version of Python, and cannot switch the version running it. You can simultaneously run IDLE 2.7 on Python 2.7 and IDLE 3.5 on Python 3.5.
When you run code from any IDLE editor, it is added your File => Recent files list, which is used for any version of IDLE you run. I frequently pull a file into another running version to see if it runs the same, perhaps after revision for known differences between 2.7 and 3.x.
At least 95% of code that people write runs the same directly in Python (with the -i flag) and IDLE. The IDLE doc, accessible under Help => IDLE Help, notes these differences.
3.2. IDLE-console differences
As much as possible, the result of executing Python code with IDLE is
the same as executing the same code in a console window. However, the
different interface and operation occasionally affects visible
results. For instance, sys.modules starts with more entries.
IDLE also replaces sys.stdin, sys.stdout, and sys.stderr with objects
that get input from and send output to the Shell window. When this
window has the focus, it controls the keyboard and screen. This is
normally transparent, but functions that directly access the keyboard
and screen will not work. If sys is reset with importlib.reload(sys),
IDLE’s changes are lost and things like input, raw_input, and print
will not work correctly.
With IDLE’s Shell, one enters, edits, and recalls complete statements.
Some consoles only work with a single physical line at a time. IDLE
uses exec to run each statement. As a result, 'builtins' is
always defined for each statement.
There are probably a few more equally esoteric things I should add.

IDLE has this feature where it suggests operations on a variable automatically or by using ctrl+space. But in terminal no such suggestion prompts appear in any case.
Not sure how you can switch versions in terminal.

Related

How to make Spyder output only python printouts in Ipython

I have some python code that runs optimization based on numbers output from fortran code using a simple os.system .out file. Previously I was able to use Spyder to run the python code and in the IPython console only the python print commands would show; this is preferred since the fortran code has lots of print messages that are useless to me but I don't want to go through and comment them out. I switched to a new computer and downloaded Anaconda 4.6.11 and Spyder 3.3.3, and now I can't recreate that situation where only the python code would print.
I've tried changing some settings in the "Run configuration per file" under the Run tab as well as the "Preferences" tab but there's nothing I can find specifically on just outputting the python code to the terminal.
os.system(MachUp.out)
I do remember that the fortran code sent its print messages in a regular terminal while the python code kept its print messages in the IPython terminal. Perhaps it's an older version of Spyder that I should use?

When to use the terms python shell and python interpreter?

1) I am new to Python and love to learn its core. I have downloaded the python software package and discovered the python.exe application inside. I double clicked it and a balck and white window popped up.
Should I call it a python Interpreter or python Shell?
2) I am learning python online. I came across the terms python tty, python shell and python interpreter. I am satisfied by calling that screen inside the window as a tty(TeleTYpewriter) because we could use only keyboard to work inside and no mouse. But actually that screen has got some intelligence responding to our request. Is python tty an apt term for it?
3) In UNIX, shell is an user interface and command line interpreter, so does python interpreter and python shell are the same.
Python shell lets you use the Python interpreter in interactive mode, just as an OS shell, such as bash, lets you use the OS in interactive mode. You can use the Python interpreter in script mode or batch mode wherein you let the interpreter execute all lines of code in one sequence. It is comparable to writing shell scripts (or batch files in Microsoft Windows).
In your case the screenshot is of a python "shell".
You shouldn't really pay attention to this distinction because in the end everything runs through the python interpreter be it in interactive mode or not.
It is both the python shell and the python interpreter. The shell is where you write your code directly in the CLI, whereas the interpreter is the program that will interpret your code and execute it. Therefore, the interpreter is called in the shell when you write some code, it may also be called when you execute some python code directly from a file.
The customary term for the interactive Python shell is the Python REPL. Many modern interpreters enter a Read-Eval-Print-Loop when you run them interactively, and this term has stuck.
The program which interprets and executes your Python code is the Python interpreter; it can act as a shell, as described above, or run silently and just execute your Python code without any visible user interface of its own, like when you run a script of yours with
python scriptname.py

Stop execution of Python script (ctrl+C) in IPython using the Anaconda distribution

I am trying to stop execution of Python scripts in IPython in Windows. I have installed Python and IPython using Anaconda. However, whenever I press Ctrl+C, it breaks out of the current Python script as well as IPython. I saw a similar post here, which said to instead launch IPython with python C:\python27\scripts\ipython-script.py (or wherever that .py script is located), but for Anaconda users that script is in C:\Users\andre\Anaconda3\pkgs\ipython-5.1.0-py35_0\Scripts\ipython-script.py (which then changes with every version number if IPython that is installed). This ends up working but is certainly not convenient. I can make a quick shortcut/keybinding that runs that ipython-script.py script, but if and when I update IPython, I'm going to have to change the shortcut, and that seems rather inconvenient.
Any suggestions? I suppose I could add C:\Users\andre\Anaconda3\pkgs to my path, but that seems a little bit of overkill since there are a ton of packages in there.

Difference Between Python's IDLE and its command line

What are the key differences between Python's IDLE and its command line environment? IDLE looks nicer, of course, and has some kind of GUI...
Moreover, is IDLE treated the same as the shell? I mean, the shell is the middle layer between the user and Python's interpreter?
They are both the same thing but, IDLE is made to write python code so its better if you can to write on IDLE. You can also try Notepad++ its a pretty good program to write code on.
I am not sure what you question is, but here is a Windows-7 oriented answer of similarity and difference. In the start menu for Python x.y, you can select 'Python x.y (x bits)' to run python interactive in a text-line-oriented console window provided by Microsoft. The console handles key presses and mouse movements and clicks. When you hit , the console sends the line of text to python, which is waiting for input on sys.stdin. When Python processes the line, it sends output to sys.stdout or sys.stderr. This includes '>>> ' and '... ' prompts. The console displays the text for you to see.
In the start menu, you can instead select 'Idle ...'. Unless you have previously selected a different startup option, python run Idle code which uses the tkinter module which used tcl/tk to run a graphical user interface that somewhat imitates the console. The tkinter/tk gui handles key and mouse input and displays output. In both cases, some software besides the Python interpreter itself handles interaction between you and Python.
Some important differences:
Cut, copy, and paste work normally. The Windows console is crippled in this respect.
Idle colors input and output. The Windows console does not.
Idle can display all unicode BMP (the first 64K) chars. The Windows console is limited by code pages.
For 1, 2, and 3, the console of other OSes may do as well or better than Idle.
Idle lets you enter, edit, send, and retrieve complete statements. Interactive python with Windows console only works with physical lines.
Update, 2017/11:
Item 1 above: At least on current Win10, cut, copy, and paste work normally.
Item 3 above: At least on Win10, unicode works better in Command Prompt with 3.6+.
New item 5: The IDLE doc section, also available as Help => IDLE Help now has section '3.3. IDLE-console differences'.
IDLE is a very simple Integrated Development Environment. It runs the same python, libraries etc. as commant-line.
Even more basic (with less features) is IPython. Full feature IDE for Python is, for example, Eclipse with PyDev plugin, or LiClipse.
Python IDLE is where you write your program/s and Python Shell is where you run your program/s.

Python shell unresponsive in emacs

I'm trying to use emacs as my python develloping environement. But I'm facing a problem.
All communication between emacs and any python interactive shell that is called by python-shell seems broken:
The shell seems to start normally, displaying versions and giving me a prompt but then as I enter commands, nothing seems to happen. I have no answer from the interpreter. I can keep writing things but they then stay there in the middle of the screen and nothing happens. I've tried setting regular python interpreter to python and ipython and nothing changes.
I also try to invoke a system shell, that works correctly, and then call python or ipython from there, that brings me back to the same "no response" situation. It just looks like a normal buffer that I can edit. I can delete through the prompt, write some character anywhere in the screen, in the version info... It doesn't looks interactive at all.
What could be the reason of this problem?

Categories

Resources