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 questions.")
print ("Do you like me %s?" % user_name)
likes = input(prompt)
print ("Where do you live %s?" % user_name)
lives = input(prompt)
print ("What kind of computer do you have?" )
computer = input(prompt)
print ("""
Alright, so you said %r about liking me.
You live in %r. Not sure where that is.
And you have a %r computer. Nice.""" % (likes, lives, computer))
sys 为内置模块,提供了许多函数和变量来处理 [Python](运行时环境的不同部分。是固定的用法,不能自己随便写名字代替它,这行的作用就是要把用到的东西(比如需要什么特定函数什么之类的)从这个东西存放的模块中引入程序中。
argv就是列表(参数变量),是编程术语。在解释器启动后, argv 列表包含了传递给脚本的所有参数, 第一个元素为脚本自身的名称。
WX20170707-150534@2x.png
网友评论