Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- ====== ===============================================================
- Character Meaning
- --------- ---------------------------------------------------------------
- 'r' open for reading (default)
- 'w' open for writing, truncating the file first
- 'x' create a new file and open it for writing
- 'a' open for writing, appending to the end of the file if it exists
- 'b' binary mode
- 't' text mode (default)
- '+' open a disk file for updating (reading and writing)
- 'U' universal newline mode (deprecated)
- ========= ===============================================================
- The default mode is 'rt'
- """
- # funciones de archivos: open(), read(), write(), close()
- # Programa que crea un archivo con temp en ºC, lo guarda y lo cierra
- # Luego lo abre, le agrega nuevos datos, lo guarda y lo cierra
- # Luego, abre el archivo, lee los datos y crea otro archivo similar pero en ºF
- # Creo un archivo en modo texto para escribirlo
- f = open("centigrados.txt","x")
- # creo una lista con los datos a guardar en el archivo
- datos = ["25ºC\n", "14ºC\n", "0.25ºC\n", "-45ºC\n"]
- # escribo los datos en el archivo (y los guardo)
- for dato in datos:
- f.write(dato)
- # cierro el archivo
- f.close()
- # abro el archivo para agregar datos (append) y lo cierro
- f = open("centigrados.txt", "a")
- datos = ["17.25ºC\n", "-18ºC\n"]
- f.writelines(datos)
- f.close()
- # abro el archivo en modo lectura
- f = open("centigrados.txt")
- datos = f.readlines()
- f.close()
- # creo el archivo farenheit.txt
- f = open("farenheit.txt","x")
- for linea in datos:
- temp, escala = linea.split("º")
- temp = float(temp) * 1.8 + 32
- f.write("{:.1f}ºF\n".format(temp))
- # cierro el archivo
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement