【Python】Learn Python the hard way, ex15 读取文件
2015-10-07 15:09
671 查看
from sys import argv script, filename = argv txt = open(filename) print "Here's your file %r:" % filename print txt.read()
txt.close() print "Type the filename again:" file_again = raw_input("> ") txt_again = open(file_again) print txt_again.read() txt_again.close() """ Test Result: bogon:~ myRMBP$ python /Users/myRMBP/Desktop/ex15.py /Users/myRMBP/Desktop/ex15_sample.txt Here's your file '/Users/myRMBP/Desktop/ex15_sample.txt': This is stuff I typed into a file. It is really cool stuff. Lots and lots of fun to have in here. Type the filename again: > /Users/myRMBP/Desktop/ex15_sample.txt This is stuff I typed into a file. It is really cool stuff. Lots and lots of fun to have in here. """
心得:
通过argv来传递文件路径和名称
相关文章推荐
- python zip用法
- 【Python】Learn Python the hard way, ex14 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 转义字符