0
import os

commands = ['uname -v', 'whoami']

a = 0  
numberIterations = 2    # How to make a command line argument of a while loop number?  
while a < numberIterations:  
    print "#--- Iteration: %s ---#" % a  
    i = 0  
    while i < len(commands):  
        print "$", commands[i]  
        os.system(commands[i])  
        i = i + 1  
    print ""  
    a = a + 1  

この形式でスクリプトを実行したい:
./script.py "numberIterations"

4

3 に答える 3

1
import sys

sys.argvコマンドラインからの引数が含まれています

http://www.tutorialspoint.com/python/python_command_line_arguments.htm

于 2013-04-18T16:03:14.920 に答える