2016-10-21 6 views
1

Python 3内でPython 3プログラムを開きたいのですが、ターゲットプログラムは別のフォルダにあります。Python 3内の別のフォルダでPython 3プログラムを開く方法

EG:Pythonloader.py> PythonFolder> Target.py

私は、任意の外部プログラムを実行するためにはPython 3.3.0

+1

「オープン」とは何ですか?手動で起動した場合と同様に起動しますか?モジュールを 'import'しますか?別のフォルダが特にこのような問題になるのはなぜですか? – deceze

+0

組織は重要です。 –

+1

それは私の質問に答えていません。 – deceze

答えて

1

使用subprocessモジュールを使用しています:

import subprocess 
subprocess.call('python3 /path/to/target.py') 

チェックhttps://docs.python.org/2/library/subprocess.htmlのためにレビュー。

あなたのスクリプト内で使用するようにコードをインポートする場合:

import sys 
sys.path.append('/path/to/containing/directory') 
import target 

は、その後、あなたが内のコードを使用することができます。

+0

これはとてもうまく動作します。私は中央のPythonプログラムでこれを使って残りの部分を学校の効率化のために開きます。 –

0

コードは正常に動作します。私は4つの数字を推測することができ、それは私のために正しく停止しました。プログラムを正しく書いたように見えますが、数字を推測することはできません。

$ python foo.py 
First >> 1 
Second >> 2 
Third >> 3 
Fourth >> 4 
* 
First >> 5 
Second >> 6 
Third >> 7 
Fourth >> 8 

First >> 1 
Second >> 1 
Third >> 1 
Fourth >> 1 
** 
First >> 2 
Second >> 2 
Third >> 2 
Fourth >> 2 
* 
First >> 3 
Second >> 3 
Third >> 3 
Fourth >> 3 

First >> 4 
Second >> 4 
Third >> 4 
Fourth >> 4 
* 
First >> 1 
Second >> 1 
Third >> 2 
Fourth >> 4 
** 
First >> 1 
Second >> 2 
Third >> 1 
Fourth >> 4 
* 
First >> 1 
Second >> 1 
Third >> 4 
Fourth >> 2 
* 
First >> 4 
Second >> 1 
Third >> 1 
Fourth >> 2 

First >> 1 
Second >> 4 
Third >> 1 
Fourth >> 2 
** 
First >> 1 
Second >> 4 
Third >> 2 
Fourth >> 1 
**** 
+1

私はすべての可能な番号を試してもまだ動作しません。 –

+0

あなたのコードは正しいですが、もっと知的に推測する必要があります。 – user2297550

関連する問題