异常处理,,def main():
文章由Byrx.net分享于2019-03-23 05:03:38
异常处理,,def main():
def main(): try: for line in readfile('lines.txt'): print(line.strip()) except IOError as e: print('could not open the file:',e) except ValueError as e: print('bad filename:',e) def readfile(filename): if filename.endswith(".txt"): fh = open(filename) return fh.readlines() else: raise ValueError("file must be ends with .txt")if __name__ == "__main__": main()
相关内容
- Python 实现半双工聊天器,python半双工聊天器,#coding=ut
- python的HTTP客户端库requests使用示例,pythonrequests,reques
- 演示异常,,#coding=utf-
- python操作sqlite,pythonsqlite,python2.5以上版
- 按日期对照片进行分类整理,日期照片分类,# -*- codin
- 每日迅雷会员爬虫,迅雷会员爬虫,None
- Python3.4 PIL的使用,Python3.4PIL使用,from PIL imp
- 分析日志,,#!/bin/env p
- django 非常实用的无限级分类功能,django非常实用,利用
- python udp 服务器,pythonudp,import socke
评论关闭