what is the difference between python shell and IDLE? - python

As python has two ways to code one from python command and one from python shell what is the difference between these two?

Python Shell is a command line tool that starts up the python interpreter. You can test simple programs and also write some short programs. However, in order to write a more complexed python program you need an editor. IDLE, on the other hand, has combined the above two needs and bundled them as a package. IDLE consists of Python Shell, and Text editor that supports highlights for python grammar and etc.

Related

Get Python Shell open

So i open Python 3.7.3 and all i get is a black window that looks like the command prompt window. Where is the shell? Where do I write my code? I saw an example with this same version of python where there were 2 white windows, one with the code and the other being the shell but i am confused how to set that up.
Is there a difference between just python 3.7.3 and IDLE? As you can see I am basically lost in this whole situation.
The window that I see looks like this: https://imgur.com/a/rMOMEh5
You have a few options, to name the basic ones:
Write your python code as a plain text file with an editor of your choice, and execute using:
python myfile.py
Write your python code in a simple IDE (e.g. sublime, atom) that has fancy features such as auto-indentation and colour coding, and execute using:
python myfile.py
Write your code in a fancy IDE that allows you to have shell and code at the same time, and execute within the IDE (e.g. PyCharm)
That's the python shell where you can issue python commands. You can call a python script as stated above and even code python directly in that window. Here is an example:
Type from secrets import token_urlsafe and hit return. Now you've imported your first python module.
Type ran_num = token_urlsafe(16) and hit return. Now we've declared a variable called ran_num and gave it the value of 16 random number, letters, and characters.
Type print(ran_num) and look at the output, which should be something like this - W2Z6O4XGebDa-eXbJY5p3Q
This is just one example. There are a lot of uses.

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

Calling to python interactive script from another script

I am using Python 2.7
I have interactive Python script, named A, written using Cmd module.
However, sometimes there is a need to activate script A from other Python scripts.
It also could be nice if the interactive script A wouldn't exit in between commands given to them.
I tried to search for solutions and I found couple here
One is to pass a file from which the interactive script will read commands. It works well for me but it is not much liked.
Another is to use echo which doesn't work for me (still trying).
I wonder whether there are other solutions.....

How to run code directly from python interpreter in Sublime Text 2?

I'm running a python script using Sublime Text 2. To run the script, I use command B--this works great until I want to explore some variable by typing it into the python interpreter, as the interpreter does not appear to be interactive. Is there any way to be able to input code into Sublime Text 2's interpreter in order to test ideas and code snippets before I add them to the main script?
I don't think sublime support it. I know you can use SublimeREPL when you need pass some users inputs.

python programming query

I'm new to Python programming.
My question is where to write python programs in linux--
in terminal or
any writing pad like gedit etc
Should we write one program again and again for running or we should call the program and run it.
After you install Python (it's installed by default on most Linux-es), you have two options:
Terminal. Just type python <ENTER> and you will be taken to the Python interpreter interactive prompt. For anything but the most basic stuff, however, you may want to intall IPython - an alternative interactive prompt that's much better than the default one.
In a file. Save your code into a .py file and run it with python myfile.py
But first and foremost, start by learning Python - the official tutorial is a great place to start. Among other useful information, its chapter 2 discusses how to use the Python interpreter for beginners.
Stackoverflow also has a lot of great resources for learning Python. This question, for example, and many others.
If you are learning, or you are evaluating expressions, you could run Python in terminal, or use IDLE.
But if you are writing large chunks of code, then you should consider using an IDE.
You could either use Geany, or use Eclipse with PyDev. I prefer Eclipse myself.
For running, you can run it using the command python program.py, or just add the line
#!/bin/python
to the beginning of your program, grant it execution permission using chmod, and run it with ./program.py command.

Categories

Resources