【Python】Learn Python the hard way, ex14 argv参数传值
2015-10-07 14:54
543 查看
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 = 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) 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) """ Test Result: Hi ghx, I'm the /Users/myRMBP/Desktop/ex14.py script. I'd like to ask you a few questions. Do you like me ghx? >yes Where do you live ghx? >sz What kind of computer do you have? >mac Alright, so you said 'yes' about liking me. You live in 'sz'. Not sure where that is. And you have a 'mac' computer. Nice. """
心得:
通过argv传值应该可以用于混合编程,值得关注
相关文章推荐
- 使用 Python 进行线程编程
- python模糊查询
- Python标准库的学习准备
- Python标准库——走马观花
- <PY>感知机
- python设计模式1:创建型模式
- 6.Python补充_Python之道
- 5.Python补充_字符串格式化 (%操作符)
- 4.Python补充_Python简史
- windows下使用cx_freeze将Python程序打包成exe可执行文件
- Python 全局变量的使用
- 【Python】Learn Python the hard way, ex13 传递参数
- Python 3.0 和 2.X的简单区别
- Python的ipython的安装
- 【Python】Learn Python the hard way, ex12 raw_input 提示别人
- python 如何找到某一目录下的文件类型(三种方法)
- 【Python】Learn Python the hard way, ex11 raw_input
- 【Python】Learn Python the hard way, ex10 转义字符
- 【Python】Learn Python the hard way, ex9 换行符,打印多行字符
- Python的Set和List的性能比较 + 两者之间的转换