标签:
import os Filename=raw_input("please input filename that you will open: ") if os.path.exists(Filename):##检查文件是否存在 try: Filehandle=open(Filename,"r") except Exception,e: ##捕获Exception的错误 存储到e里面。其中Exception是异常的基类 print e else: for words in Filehandle: print words Filehandle.close() else: print "%s not exits"%Filename
标签:
原文地址:http://www.cnblogs.com/paulwinflo/p/4213755.html