Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 13, 2022 00:25
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/0448659b604df51bd97c2ec50811418a to your computer and use it in GitHub Desktop.
Save parzibyte/0448659b604df51bd97c2ec50811418a to your computer and use it in GitHub Desktop.
# 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