返回顶部

收藏

Handling I/O Errors

更多
# shows how to safely open and read from a file and gracefully handle errors.

try:                                          
   fsock = open(filename, 'rb', 0)             
   try: 
       fsock.seek(-128, 2)                     
       tagdata = fsock.read(128)               
   finally:                                    
       fsock.close() 
except IOError:                                
    pass 

标签:Python,File

收藏

0人收藏

支持

0

反对

0

发表评论