Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Script para agregar una línea de texto que diga hola a un archivo
- # uno.txt, si el archivo no existe lo crea
- try:
- f = open("uno.txt", "x") # intento hacer esto
- except FileExistsError:
- f = open("uno.txt","a") # ejecuto esto si da error
- else:
- print("Creando archivo uno.txt") # ejecuto esto si no da error
- finally:
- f.write("Hola\n") # ejecuto esto
- f.close() # siempre
- """
- ejecuta try --> else --> finally si no hay error
- ejecuta try --> except --> finally si da error
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement