Ich habe den folgenden Code:Befehl von Array mit Subprozess aufrufen?
'''
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
Und es gibt mir die folgende Fehlermeldung geben:
File "/home/ubuntu/workspace/source.py", line 23
print ccommand[command][3:len(ccommand[command]-1)]
^
SyntaxError: invalid syntax
Process exited with code: 1
Die example.shs
Datei sieht wie folgt aus:
run rm wha;
run git clone https://github.com/jel-lang/jel.git;
Wie Sie sehen können, Dies ist eine benutzerdefinierte Sprache, die ich gemacht habe. Ich möchte, dass die Python-Datei die ersten 4 Buchstaben und die letzte aus jedem Element in der Liste nimmt und dann unter Verwendung von subprocess
.