Double-click Python files and they disappear in an instant after a black screen appears

Asked 2 years ago, Updated 2 years ago, 30 views

After downloading the Python file from online, it was expanded.Then, when you open the file, the black screen (prompt) appears for a moment and disappears immediately.I tried rebooting, but it looks the same.

Additional
Now I'm learning O'Reilly's book called "Deplearning" from scratch.
https://github.com/oreilly-japan/deep-learning-from-scratch
Downloaded data from ↑.

python

2022-09-30 21:47

3 Answers

If you are starting programming, we strongly recommend that you obtain a tool called the text editor, code editor, or IDE (Integrated Development Environment).

For example:
https://code.visualstudio.com/

If you really want to check the contents of the file right now, you can see it directly on GitHub.

https://github.com/oreilly-japan/deep-learning-from-scratch/blob/master/ch01/hungry.py

The above is a link to the contents of hungry.py.

Enter a description of the image here

Only one line

print("I'm hungry!")

You can see that it says

If you want to run the file, as some of you may see in the comments,

https://github.com/oreilly-japan/deep-learning-from-scratch#%E5%AE%9F%E8%A1%8C%E6%96%B9%E6%B3%95

I think it would be good to do it by referring to the .

Just to be sure, here are the following parts:

$cdch01
$ python man.py

$ cd../ch05
$ python train_nueralnet.py


2022-09-30 21:47

It depends on which file you opened, but if you double-click ch01\man.py, for example,
The black screen appears and disappears immediately, which is the correct behavior.

The window closes so fast that it's hard to understand, but the program that displays the string is working.

Enter a description of the image here

See what kind of program it is
If it's a program written by someone other than you, such as what's in a book or what's on the web, first check out what the program does.

See how to run the program
Python can handle the GUI depending on how you write it, but it's basically a text-based programming language.It's different from what I usually use on Windows when I double-click to start a program.
If you're looking at a book, take a closer look at the instructions provided.

If you modify the program as shown below, you will still be able to see the results for a few seconds even if you double-click it.

man.py

#coding:utf-8
import time### Additional part (part 1)
Class Man:
    """Sample class"""

    def__init__(self, name):
        self.name = name
        print("Initialized!")

    def hello(self):
        print("Hello" + self.name + "!")

    def goodbye(self):
        print("Good-bye" + self.name + "!")

m = Man ("David")
m.hello()
m.goodbye()
time.sleep(5)###Additional part (part 2)


2022-09-30 21:47

In Windows, right-click the file you want to open, click Open from the program, and then select the environment you want to open (such as Notepad).It was my own experience, but it's easy.


2022-09-30 21:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.