Ex�cuter du code python dans un string (python -c cmd)
Bonjour,
J'ai une question b�te. Comment ex�cuter du code python dans un string en appelant le code python avec l'argument "-c" ?
Code:
python -c 'for i in range(5): print i; print i+10'
Output :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
0
10
1
11
2
12
3
13
4
14 |
Supposez que je veuille ex�cuter ce code en une ligne :
Code:
1 2 3 4 5 6
|
for i in range(5):
print i
print i+10
print "end" |
La ligne suivante ne marche �videmment pas :
Code:
python -c 'for i in range(5): print i; print i+10'; print "end"
Output :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
0
10
end
1
11
end
2
12
end
3
13
end
4
14
end |
Alors que j'aurais voulu juste un print "end" � la fin.
Merci d'avance,
piloupy