這是我如何解決這個(注:你仍然必須提供的參數在最初運行腳本)
from sys import argv
script, first, second, third = (argv)
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
first = raw_input("\nNew First Variable? ")
second = raw_input("New Second Variable? ")
third = raw_input("New Last Variable? ")
print "\n\nYour new variables are %s, %s, and %s" % (first, second, third)
這裏是我得到的輸出:
C:\Users\mbowyer\Documents\Python_Work>python ex13a.py 1 2 3
The script is called: ex13a.py
Your first variable is: 1
Your second variable is: 2
Your third variable is: 3
New First Variable? a
New Second Variable? b
New Last Variable? c
Your new variables are a, b, and c
C:\Users\mbowyer\Documents\Python_Work>
如果你發佈了一些沒有坐在辦公桌上的本書的代碼,那就太好了。 – jdi 2012-02-18 02:25:08
作爲參考,正在討論的練習在這裏:http://learnpythonthehardway.org/book/ex13.html – checkorbored 2012-02-18 02:25:21