练习十三
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)
练习十四
from sys import argv
script, user_name = argv
prompt = '>'
print ("hi %s I\'m the %s script.") %(user_name, script)
print("I'd like to ask you a few question.")
print("dou you like me, %s") % user_name
likes = raw_input(prompt)
print("where do you live %s") % user_name
lives = raw_input(prompt)
print("What kind of computer do you have?")
computer = raw_input(prompt)
练习十五
#加载模块
from sys import argv
#设置变量字符串列表
script, file_name = argv
#打开文件
text = open(file_name)
#打印肉,文件名格式化
print("Here's your file %s:") %file_name
#打印文件内容,使用read()函数
print(text.read())
text.close()
#打印文字
print("Type the file_name again:")
#接收屏幕输入
file_again = raw_input("请输入文件名> ")
#打开屏幕屏幕输入的文件名
text_again = open(file_again)
#打印文件内容,使用read
print(text_again.read())
练习十六
from sys import argv
script, filename = argv
print("We're going to erase %r." % filename)
print("If you don't want that, hit CTRL-C(^C).")
print("If you do want that, hit RETURN.")
raw_input("?")
print("Opening the file...")
target = open(filename, 'w')
print("Truncating the file. Goodbye!")
target.truncate()
print("Now I'm going to ask you for three lines.")
line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")
print("I'm going to write these to the file.")
target.write(line1+'\n'+line2+'\n'+line3)
#target.write("\n")
#target.write(line2)
#target.write("\n")
#target.write(line3)
#target.write("\n")
print("And finally, we close it.")
target.close()
练习十七
#加载模块
from sys import argv
#设置变量字符串列表
script, file_name = argv
#打开文件
text = open(file_name)
#打印肉,文件名格式化
print("Here's your file %s:") %file_name
#打印文件内容,使用read()函数
print(text.read())
text.close()
#打印文字
print("Type the file_name again:")
#接收屏幕输入
file_again = raw_input("请输入文件名> ")
#打开屏幕屏幕输入的文件名
text_again = open(file_again)
#打印文件内容,使用read
print(text_again.read())