2016-05-05 7 views
0

私は次のコードを持っている:サブプロセスによる配列からのコマンドの呼び出し?

''' 
Created by Baran Skistad, bjskistad on GitHub. 
Please give credit to Baran Skistad if you use this. 
''' 
index = 0 
file = 'example.shs' 
data = '' 
loop = 0 
loopString = '' 
commands = [''] 
command = 0 
done = False 
import subprocess 

with open(file, 'r') as myfile: 
    data = myfile.read().replace('\n', '') 

commands = [part + ';' for part in data[:-1].split(';')] 
print commands 
if done: 
    while command <= len(commands): 
     ccommand = commands[command] 
     print ccommand[command][3:len(ccommand[command]-1)] 
     subprocess.call([ccommand[3:len(commands[command]-1)]]) 
     command = command + 1 

そして、それは私に次のエラー与えている:

File "/home/ubuntu/workspace/source.py", line 23 
    print ccommand[command][3:len(ccommand[command]-1)] 
       ^
SyntaxError: invalid syntax 


Process exited with code: 1 

example.shsファイルは次のようになります。

run rm wha; 
run git clone https://github.com/jel-lang/jel.git; 

あなたが見ることができるように、これは私が作ったカスタム言語です。私がPythonファイルにしたいのは、リストの各項目の最初の4文字と最後の1文字を取り出してから、subprocessを使って実行することです。

答えて

0

これはPython 2のコードであり、Python 3で実行しています。コマンドpython2で実行すると、問題は発生しません。

関連する問題