Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- open: abre un archivo
- read: retorna el contenido del archivo abierto
- write: escribe en un archivo abierto
- close: cierra un archivo abierto
- ********** OPCIONES DE OPEN ********************************
- ========= ===============================================================
- Caracter Significado
- --------- ---------------------------------------------------------------
- 'r' abre para lectura (default)
- 'w' abre para escritura, borra el archivo primero
- 'x' crea un archivo nuevo y lo abre para escritura
- 'a' abre para escritura, añadiendo contenido al final del archivo
- 'b' modo binario
- 't' mode texto (default)
- '+' abre un archivo en disco para actualizar (lectura y escritura)
- ========= ===============================================================
- """
- # Script que hace lo siguiente:
- # 1. Crea un archivo 'celsius.txt', le carga datos de temperaturas y lo cierra
- # 2. Crea un archivo 'farenheit.txt'
- # 3. Abre el archivo 'celsius.txt', lee los datos y lo cierra
- # 4. Pasa los datos a ºF, los guarda en 'farenheit.txt' y cierra el archivo
- ############## Paso 1
- f = open('celsius.txt', 'x')
- datos = ["10ºC\n", "15.2ºC\n", "22ºC\n", "15ºC\n", "32ºC\n"]
- # Escribo datos de 2 maneras
- # manera 1
- # f.writelines(datos)
- # manera 2
- for dato in datos:
- f.write(dato)
- f.close()
- ############## Paso 2
- f1 = open('farenheit.txt', 'x')
- ############## Paso 3
- f2 = open('celsius.txt')
- # Leo datos
- lineas = f2.readlines()
- f2.close()
- ############## Paso 4
- for linea in lineas:
- temp, escala = linea.split("º")
- temp = float(temp) * 1.8 + 32
- f1.write("{:.1f}ºF\n".format(temp))
- f1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement