This file contains hidden or 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
import csv | |
# importamos el módulo | |
with open('ejemplo.csv') as datos_en_bruto: | |
# datos_en_bruto contiene el manipulador del archivo CSV | |
datos_estructurados = csv.reader(datos_en_bruto) | |
# el método reader lee el archivo que se le pasa como parámetro | |
# y devuelve en datos_estructurados una estrucura que se puede usar en python: | |
# una lista con un elemento por cada fila que, | |
# a su vez, contiene una lista por cada campo |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Métodos "privados" | |
class MiClase: | |
variable_a_nivel_de_clase = "cosa" | |
def __init__(self,texto): | |
self.nombre = texto |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Métodos "privados" | |
class MiClase: | |
def __init__(self,texto): | |
self.nombre = texto | |
def metodo(self): | |
print(self.nombre + " Público") |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Ambas funciones son casi idénticas, pero varían en cómo reciben los parámetros: | |
def funcion_args(*cosas): | |
print(cosas) | |
def funcion_kwargs(**cosas): | |
print(cosas) |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Ejemplo de llamada a un módulo | |
# Importamos el módulo y le asignamos un alias | |
import mi_modulo as mm | |
# Llamanos a la función con el alias | |
mm.mi_funcion("hola") |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Ejemplo de módulo | |
def mi_funcion(cadena): | |
if cadena == "hola": | |
print("ha dicho hola") |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Ejemplo de llamada a un módulo | |
# Importamos el módulo usando su nombre sin la extensión | |
import mi_modulo | |
# Llamanos ala función con el nombre del módulo antepuesto y seprarado por un punto | |
mi_modulo.mi_funcion("hola") |
This file contains hidden or 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
#!/usr/bin/python3 | |
# Creamos una variable y mostramos el ID | |
variable = 1 | |
print(id(variable)) | |
# la incrementamos en dos y volvemos a mostrar el ID | |
variable += 2 | |
print(id(variable)) |
This file contains hidden or 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
#/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Copiando listas | |
# creamos una lista: | |
primera_lista = [1, 2, 3] | |
# la copiamos en otra: |
This file contains hidden or 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
#/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Ejemplo de listas e IDs | |
# creamos una lista: | |
primera_lista = [1, 2, 3] | |
# la copiamos en otra: |
NewerOlder