/
diev
/
swaroopch-byte-of-python
Обзор
Документация
Войти
/
diev
/
swaroopch-byte-of-python
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
programs/exceptions_finally.py
24 строки
563 B
Swaroop C H
Add programs folder
19 янв 2016, 18:47
19 янв 2016, 18:47
ed99d1b
Код
Авторство
О чём код?
import sys import time f = None try: f = open("poem.txt") # Our usual file-reading idiom while True: line = f.readline() if len(line) == 0: break print(line, end='') sys.stdout.flush() print("Press ctrl+c now") # To make sure it runs for a while time.sleep(2) except IOError: print("Could not find file poem.txt") except KeyboardInterrupt: print("!! You cancelled the reading from the file.") finally: if f: f.close() print("(Cleaning up: Closed the file)")