[Python] python读写文件并进行异常处理代码演示 →→→→→进入此内容的聊天室

来自 , 2021-04-02, 写在 Python, 查看 126 次.
URL http://www.code666.cn/view/9c449771
  1. #!/usr/bin/python
  2.  
  3. try:
  4.    fh = open("testfile", "w")
  5.    fh.write("This is my test file for exception handling!!")
  6. except IOError:
  7.    print "Error: can\'t find file or read data"
  8. else:
  9.    print "Written content in the file successfully"
  10.    fh.close()
  11. #//python/8340

回复 "python读写文件并进行异常处理代码演示"

这儿你可以回复上面这条便签

captcha