Why this did not give an output using atom text editor?

when I run
a = "Hello world "
a
if I save this two line code and run it from PowerShell it does not give any output whereas on IDLE it does.
Is it due to the reason that storing a value and printing it are two different things. If this is true then to output anything I will always require a print() function, simply entering the variable ‘a’ (like I did above) won’t work?

1 Like

Yes. The REPL echoes the value of every expression that you type. In a script it’s different, you need to to print things explicitly.

Thanks Florian. I am a beginner programmer, so I will try and understand your reply.
I googled REPL. So IDLE is REPL, it outputs each and every line (just about everything). Whereas when we run a code from the Shell it outputs the entire program.
So when I type python in Shell and run it, I enter an environment similar to IDLE/REPL which is nothing but the Python Interpreter itself, right? Or is it an interface with Python Interpreter?

Yes.

Honestly I’m not sure about the nomenclature here either. You basically get the Python interpreter in interactive mode.

Hi Aniruddha ! I had the same problem : no output at ex1. Maybe you are a beginer non programmer like me. For me the solution was very simple but very long to find out (several hours) :

But i just had to save my code before running it through powershell lol… long way to go :’)

Welcome @Gab1 and @Aniruddha :slight_smile:

A simple way to look at it is: using the python interpreter (through IDLE shell or by executing python on your command line) provides you with a way to interact with python in real time by using the programming syntax.

See this example below from IDLE. I tried to print ‘Hello’ but skipped the closing speech marks, and it threw an error immediately when I hit return to go to the next line. (That’s what REPL does; read, evaluate, print, loop. It read my instruction to print “hello”, evaluated it as containing an error, printed the error it found as best it could, and reset the loop ready for the next command.

Python 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> print("Hello)
      
SyntaxError: EOL while scanning string literal
>>> 

I’m interacting with python directly in realtime.

However, when you are writing a script/file, you are not running it in realtime, but writing something to ‘run’ later. So I can declare thing, gives instructions or actions, and save it. Because I am not getting that read, evaluate, print and loop behaviour, I can even save the error again (missing speech marks) and the file saves no issue.

It’s only when I try to run the file, telling my computer to use the python program to run a file called hello.py (where I saved my code):

python hello.py

Do I get the error flagged at me, because python is now running each line in the script.

gpkesley$ python hello.py
  File "hello.py", line 1
    print("Hello)
                ^
SyntaxError: EOL while scanning string literal

You’ll get plenty more practice with writing a script, and running code snippets directly in the python interpreter as you progress so don’t worry.

2 Likes

Indeed. Very long way to go!

Hello gpkesley thank you so much for your answer. I learned what REPL and snippet mean now thx !!.