This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 7 months ago.
I wrote a factorial program in Sublime text editor. After executing the program using the shortcut key Ctrl + B only the first print statement is getting executed. However, I tried using the shortcut key Ctrl + Shift + B and the result is the same.
The problem is that proper execution is not achieved and I am unable to figure out the issue which is causing the problem.
Here is an image of the above-mentioned situation. As you can clearly see that I am following the conventions to execute the code. However, only the first line is executed.
Although I tried the same code in default Python IDLE I got the result. As such I don't think the code is wrong. Is it due to some IDE issue or have I not installed the sublime text editor properly.
Your code isn't wrong; the problem is that Sublime doesn't support interacting with a running program without extra work. Although it connects stdout and stderr to the output panel so that output your program generates can be displayed, it doesn't connect stdin to anything.
What you see is yourself typing 34 into the output panel, but your program doesn't see that and just sits in the background forever waiting for input that you can't provide until you kill it.
In order to run an interactive program like this from Sublime, you need to create your own sublime-build file that either opens an external terminal and runs the program there, or one that utilizes a package such as Terminus to open a terminal within Sublime and run the program there. Both of those require you to know what command you need to run in the terminal in order to run your program in order to set up the build.
An example of using Terminus for this task (using C and not Python, so you'd need to adapt it) can be found in this video on buffering and interactive builds in Sublime (disclaimer, I'm the author).
Related
In VS Code, I have two terminals open. In one of them, I have python activated (as I like to tinker with my python code). The problem is, when I attempt to run my python file, VS Code tries to execute it in that terminal (the one with python activated), so the file obviously does not run.
Is there a way to fix this annoying behavior?
Consider the following scenario: I have two Python scripts, the first a long-running process and the second a short-running process. I heavily use the shift + enter shortcut to run code directly from my .py files.
Currently in VS Code, I can only manage to have the interactive environment with one script. That is, if I run the first, long-running script and then open a new Python terminal window, running a line such as print('hello world') will run in the first terminal. I want to learn how to change the shift + enter so that it executes in the second, newly-opened terminal window.
I've looked at a few SO questions, namely this one, but the solutions either don't work or are not applicable to my use case.
I managed to execute in the newly-opened terminal window typing a command there. Not as convenient as shift + enter but does the job.
When you run a python script from terminal and before it completes running of you control + c it, it gives a traceback where the code was currently running. Is it possible to see which part of a code is running without terminating it.
in pycharm, you can debug by selecting code areas that you want to work, and by pressing next and next, you'll see how does program running it, without terminating it.
You can do this in PyCharm using the debugging facility. It allows you to step through your code line by line, running each line as you pass it. You can see what variables have been assigned etc. Very helpful for debugging!
See here: https://www.jetbrains.com/help/pycharm/part-1-debugging-python-code.html
I know some basics of Java and C++, and am looking to learn Python
I am trying to develop some random stuffs to get a good feel of how it works, but i can only make 1 line scripts that run every time i press enter to go to the next line.
I've seen tutorial videos where they can just open up files from a menu and type away until they eventually run the program.
I'm using IDLE, and i don't see options to open up new stuffs; I can only make one or two line programs. When i tried to make a calculator program, i didnt know how to run it because it ran every line of code i typed in unless there were ...'s under the >>>'s.
I think it's because i am in interactive mode, whatever that is.
How do i turn it off, if that's the problem?
There are many different options for writing python scripts. The simplest to use is Idle, it come with the Python download. Within Idle, create a new document to write a script. Once finished, save it as a .py file, and you can run it within Idle. For my personal setup, I use the text editor Atom. I can create documents easily, and run them through the terminal on my computer. Hope this helps.
To exit out of the "interactive mode" that you mentioned (the included REPL shell in IDLE) and write a script, you will have to create a new file by either selecting the option from the top navigation bar or pressing Control-N. As for running the file, there's also that option on the navigation bar; alternatively, you can press F5 to run the program.
Greetings dear community,
I am currently using Sublime Text 2 (Unregistered) as my coding agent. And there is a strange behavior i noticed lately. When i am running a code in sublime text(Through build, with CTRL-B), if a code needs long time to run, like an infinite loop, I try to cancel the build(I specified CTRL-SHIFT-B to cancel build), sublime text shows me a message that build is cancelled
[Cancelled]
like so. In regular command line this means python program is no longer running. As I think it should be the same in sublime text, however, it is not. As longer i keep trying to cancel than build again, more and more python.exe keeps showing in the task manager. I can have like 10 python.exe running behind if I don't end process manually through task manager. Can somebody explain this behavior to me please ? And the reason behind it, can I prevent it ?
By the way, I tested the Python IDLE, and command prompt before asking so i could provide more information
Python IDLE shows same behavior and keeps python exe's running after cancelling.
Command prompt stops the process with no problem.
I am using python2 in a windows 8.1 system.
Thanks in advance for your time.