Home > other >  How do I stop Python from running code right after I type it in?
How do I stop Python from running code right after I type it in?

Time:07-22

I just started to code on Python, so I downloaded the "Python 3.10 (64-bit)". The problem is that it runs the code without my permission. For example, if I am trying to type in print("example") it just runs on it's own. This means I can't do an actual coding project, it just runs the 1 piece of code right after I hit the Enter button. I don't know if I'm just blind or it's obvious, but I can't figure it out. What do I do?

CodePudding user response:

Hitting enter after you type is "giving permission" to run the code that is typed (or copied)...

You can still write "scripts" this way - you define variables, functions, classes, etc, and they remain in scope of the interactive session.

If you want to "code a project," though, you should use an external IDE such as Visual Studio Code, PyCharm, Spyder, etc. The built-in IDLE is very basic, but still does allow for file execution.

CodePudding user response:

Where do you write your code? If you are using the command line, you cannot do anything to change this; you have to use a file with the extension ".py", for example "first_file.py", and write the code inside that file. When you are done or when you want to test your code, you have to open the terminal in the file folder and type python [filename].py and after that, your code will be compiled and executed in the terminal. I recommend using a code-writing program like VS Code, Atom or something like that.

  • Related