0

シンプルな python スクリプトを実行可能にしようとしたため、何をすべきかをグーグルで調べました。これが私がこれまでに得たものです

。デスクトップ

[Desktop Entry]
Version=1.0
Type=Application
Name=helloworld
Comment=
Exec=./test.py
Icon=
Path=/home/xxx/Desktop
Terminal=true
StartupNotify=false

pythonファイル

#!/usr/bin/env python
print('hello world')

端末で chmod +x test.py を実行したところ、./test.py を介して端末で実行できるようになりました。

デスクトップ アイコンをダブルクリックすると、ターミナルが非常に短い時間だけ開いているのがわかりますが、すぐに閉じてしまいます。

私は何を間違っていますか?

デスクトップ アイコンでターミナルが開き、Python スクリプトが表示されることを期待していました。

ありがとうございました

4

2 に答える 2

3

スクリプトが終了すると、ターミナル ウィンドウが閉じます。あなたが置くことができます

input()     # Python 3
raw_input() # Python 2

エンターキーを押すと閉じます。

于 2013-09-28T14:55:24.340 に答える
0

正しい方法ではない@Veedrac。正しい方法はtime.sleep()、Python 3.x と 2.x の両方で動作する whichを使用することです。これを行うには、次のコードを使用します。

import time # Should be the first statement.
# Some code is below. This code is useless. 
print()
def blah():
    print('bhahfdjfdk')
blah()
# When the program ends, use the code below to keep it running for some more time.
time.sleep(2) # In the parentheses you can replace 2 with the number of seconds you want to put the program on hold. This will help you and is the official Python way.
于 2014-10-17T07:03:44.840 に答える