读写文件ex15.py

2018-05-14  本文已影响10人  一盏省油的小灯

ex15.py


from sys import argv

script,file_name = argv

with open(file_name, mode='r') as f:
    txt = f.read()

print "Here's your file %r:"%file_name

print txt

运行结果:

J:\python\program\ex>python ex15.py  ex15_sample.txt
Here's your file '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.
上一篇 下一篇

猜你喜欢

热点阅读