Leer un archivo con Python- try-catch-finally

#!/bin/python # coding=utf-8 #Fer Carraro msg = "El archivo existe" try: file = open("datos.dat","r") existe = True if file != None else False except IOError as error: msg = "El archivo no existe o la ruta no es la correcta" print error finally: print msg if existe: print "Contenido:" for line in file: print line file.close()

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.