M
M
Max Bogachov2016-08-16 11:40:44
Python
Max Bogachov, 2016-08-16 11:40:44

Stopping a program in Python 3.5?

OC: Microsoft Widows 7 Ultimate
Python version: 3.5
Development environment: Sublime Text 3
Hello everyone! Let's say I need a program that displays 2 inscriptions

print ("Hello")
print ("world!")

and you need to run it not through the command line, but from a shortcut. But as soon as it starts and closes right away. Help!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Max Bogachov, 2016-08-18
@Geekinder

Since no one decided to give me an adequate answer, then I myself found the solution by accident print("Hello, world")
. when you start it not from the command line, it immediately opens and closes, you need to use time:

import time

print("Hello, world")
time.sleep(6)#К примеру 6 сек

after all, stopping a python program except for input and bat is possible and quite simple!

A
Artem @Jump, 2016-08-16
curated by the

But as soon as it starts and closes immediately
This is normal and natural behavior of the program.
As soon as the program is fully executed, it closes.
Your program should print two lines to the console and exit.
She actually does it regularly and does it - in a hundredth of a second it displays two lines and completes the work, you just do not have time to see them.
You can pause the execution of commands and be guaranteed to show the output to the user in different ways - one of the options given above is adding input (), then the program will wait for input from the user.

V
Vladimir Kuts, 2016-08-16
@fox_12

Add read from console at the end
input()

A
Alexander Pozharsky, 2016-08-16
@alex4321

Personally, I see a more correct solution with a script (since Windows is .bat-m).

@echo off
python3 script.py
pause

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question