Skip to main content
 首页 » 编程设计

python之else : after a try/except clause有什么用

2025年05月04日18grandyang

<分区>

Possible Duplicates:
when is it necessary to add an else clause to a try..except in Python?
Python try-else

for arg in sys.argv[1:]: 
    try: 
        f = open(arg, 'r') 
    except IOError: 
        print 'cannot open', arg 
    else: 
        print arg, 'has', len(f.readlines()), 'lines' 
        f.close() 

这个else子句有什么用,什么时候执行?