Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

python - Sublime Text not showing me any output on a simple task

Any idea what I am doing wrong in Sublime Text?

favourite_language = 'Python   '
favourite_language
Output:
[Finished in 0.1s]

All i get is the finished message, using other platforms, such as Jupyter Notebook outputs as predicted: Output in Jupyter Notebook: 'Python '

question from:https://stackoverflow.com/questions/65913696/sublime-text-not-showing-me-any-output-on-a-simple-task

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your issue isn't Sublime related and instead is related to the fact that you're expecting a REPL environment when there isn't one. This isn't unique to using Sublime and it's also not unique to Python.

REPL stands for Read, Evaluate, Print, Loop. What this means is that the environment expects you to enter a line of code, which it then evaluates, printing the result, then going back to ask you for more information. There are many environments that present themselves as a REPL, such as executing Python with no script, executing the NodeJS interpreter with no script, the development tools in your browser, etc.

While Python does indeed include a REPL environment, and some things like Jupyter present themselves that way, that doesn't apply to what you're trying to do here. What you're doing is creating a Python file and then asking the external Python interpreter "Please run this program". This does exactly that; the Python interpreter loads and compiles your script, then runs it from top to bottom, then stops.

The code in your example assigns a value to a variable and then just references the variable; there is no call to print() to ask the Python interpreter to print the result of anything, so it doesn't. Instead it dutifully stores the value in the variable and then it's done.

More information on the REPL concept can be found here: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...