1

I'm starting out my adventure with Python, so I apologise if there are inaccuracies in my question. I have written a simple module with one command of:

print("test")

After saving the file to a .py extention I was trying to run it within a cmd terminal. Unfortunatelly a sub-shell of sorts pops out and immediately disappears. I would like the script to open within the same terminal, not open in a new one/sub-shell. What could be the cause of such behaviour? Thank you!

5
  • 1
    So just how do you run it within a cmd terminal? Commented Dec 26, 2020 at 17:45
  • Let say I have saved the file on my desktop. I'm opening the terminal and navigating my way to Desktop directory, typing in "test.py" and running the module Commented Dec 26, 2020 at 17:51
  • Does How to stop Python closing immediately when executed in Microsoft Windows answer your question? Or Window closes immediately after running program? Commented Dec 26, 2020 at 17:52
  • Ohters searching with variations of python run script window pops up and closes site:stackoverflow.com Commented Dec 26, 2020 at 17:55
  • @wwii, partially, but the threads came in handy anyway. Thank you! Commented Dec 26, 2020 at 17:56

2 Answers 2

0

In windows when you just type the name of a file, it will try to find an application to run the file for you based on the extention. For example, typing in file.txt might cause NotePad.exe to run. Similarly, typing test.py may cause windows to find a python interpreter to run your script.

These may or may not run in their own windows. However, if you enter python test.py, then windows will be looking for python, and once found to be an application already, will run it with the whole command line.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That explains a lot. Have a good one!
0

You mentioned cmd terminal so I would assume you mean windows command prompt.

I would ask that you clarify which command you are using to execute the python file.

Consider trying:

python filename.py

It should run the program on same prompt.

3 Comments

I haven't been using any commands to execute the python file. Your sugestion worked! Thank you! The cause of my problem was not running the file through an interpreter, but simply trying to display its contents. Is that correct?
yes that's the default behavior
No, if you want to display the contents of a file you could enter type test.py

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.