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

5.2k Views Asked by At

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:

  1. How can I switch between two versions in the IDLE or the terminal?
  2. What's the difference between coding in the IDLE or the terminal?
2

There are 2 best solutions below

2
On
  1. 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.

  1. 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.

1
On

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.