Created
March 13, 2022 00:25
-
-
Save parzibyte/0448659b604df51bd97c2ec50811418a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://parzibyte.me/blog | |
def obtener_csv_como_lista_de_diccionarios(nombre_archivo): | |
separador = "," | |
with open(nombre_archivo, encoding="utf-8") as archivo: | |
next(archivo) # Omitir encabezado del archivo | |
alumnos = [] | |
for linea in archivo: | |
linea = linea.rstrip("\n") # Quitar salto de línea | |
columnas = linea.split(separador) | |
nombre = columnas[0] | |
edad = int(columnas[1]) | |
altura = float(columnas[2]) | |
matricula = columnas[3] | |
alumnos.append({ | |
"nombre": nombre, | |
"edad": edad, | |
"altura": altura, | |
"matricula": matricula, | |
}) | |
return alumnos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment