Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 8, 2019 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/08c50c21450875177cccceb989101188 to your computer and use it in GitHub Desktop.
Save parzibyte/08c50c21450875177cccceb989101188 to your computer and use it in GitHub Desktop.
"""
Escribir datos en un archivo con Python
Ejemplo 3: excepciones
https://parzibyte.me/blog
"""
nombre_archivo = "."
try:
with open(nombre_archivo, "a+") as archivo:
archivo.write("Hola, escribiendo texto\n")
archivo.write(
"Cada que ejecutes el archivo, el texto se agrega al final\n")
archivo.write("parzibyte.me")
archivo.write("\n")
# No olvides cerrar el archivo
archivo.close()
except Exception as e:
print("Error abriendo archivo:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment