Download - Tecnologías web + Python
![Page 1: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/1.jpg)
< Tecnologíasweb />
Víctor R. Ruiz <[email protected]>Tenerife, 17 de noviembre de 2011
jueves 17 de noviembre de 11
![Page 2: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/2.jpg)
Internet
jueves 17 de noviembre de 11
![Page 3: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/3.jpg)
Internet
http://es.wikipedia.org/wiki/Archivo:Internet_map_1024.jpg
jueves 17 de noviembre de 11
![Page 4: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/4.jpg)
Internet• Red de redes global.
• Protocolo abierto: TCP/IP.
• Cada ordenador tiene una dirección (IP).
• Las comunicaciones se realizan por paquetes
• TCP/UDP.
• Protocolos.
• IP/Puerto.
• DNS.
jueves 17 de noviembre de 11
![Page 5: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/5.jpg)
WWW
jueves 17 de noviembre de 11
![Page 6: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/6.jpg)
WWW != Internet
jueves 17 de noviembre de 11
![Page 7: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/7.jpg)
WWW
•Protocolo de comunicación: HTTP
•Formato de contenidos: HTML
jueves 17 de noviembre de 11
![Page 8: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/8.jpg)
WWW
http://es.wikipedia.org/wiki/Archivo:First_Web_Server.jpg
jueves 17 de noviembre de 11
![Page 9: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/9.jpg)
WWW: HTTP
http://es.wikipedia.org/wiki/Hypertext_Transfer_Protocol
jueves 17 de noviembre de 11
![Page 10: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/10.jpg)
WWW: HTML
jueves 17 de noviembre de 11
![Page 11: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/11.jpg)
•Etiquetas
•<div></div>
•Atributos
•<a href=””>linotipo.es</a>
•Hojas de estilo
•JavaScript
WWW: HTML
jueves 17 de noviembre de 11
![Page 12: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/12.jpg)
Formatos de intercambio de datos
jueves 17 de noviembre de 11
![Page 13: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/13.jpg)
CSVValores separados por comas
http://es.wikipedia.org/wiki/CSV
jueves 17 de noviembre de 11
![Page 14: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/14.jpg)
XML
http://es.wikipedia.org/wiki/XML
jueves 17 de noviembre de 11
![Page 15: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/15.jpg)
XML
jueves 17 de noviembre de 11
![Page 16: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/16.jpg)
JSONJavaScript Object Notation
http://es.wikipedia.org/wiki/JSON
jueves 17 de noviembre de 11
![Page 17: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/17.jpg)
Introduccióna Python
jueves 17 de noviembre de 11
![Page 18: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/18.jpg)
Python
http://www.tiraecol.net/modules/comic/
jueves 17 de noviembre de 11
![Page 19: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/19.jpg)
Python
• Lenguaje interpretado.
• Fuertemente tipado.
• Fácil de acceder a librerías en C.
• Prototipado rápido de aplicaciones.
• Muy productivo.
• Librería estándar fácil de usar.
• Lenguaje oficial Google: Python, Java, C++
jueves 17 de noviembre de 11
![Page 20: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/20.jpg)
Python
•En Python no hay corchetes para indicar bloques.
• Los bloques se indican con identación.
jueves 17 de noviembre de 11
![Page 21: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/21.jpg)
Python: Funciones
def nombre_funcion(): ... return
jueves 17 de noviembre de 11
![Page 22: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/22.jpg)
Python: Parámetros
def nombre_funcion(p1, p2): ... return p1
jueves 17 de noviembre de 11
![Page 23: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/23.jpg)
Python: Doc string
def primer_parametro(p1, p2): “”” Esta función devuelve el primer parámetro ””” return p1
jueves 17 de noviembre de 11
![Page 24: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/24.jpg)
Python: print
def imprimir(p1, p2): “”” Imprime los parámetros “”” print p1, p2
imprimir(“a”, “b”)
jueves 17 de noviembre de 11
![Page 25: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/25.jpg)
Python: Formateo print
def imprimir(p1, p2): “”” Imprime los parámetros “”” print “%s - %s” % (p1, p2)
imprimir(“a”, “b”)
jueves 17 de noviembre de 11
![Page 26: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/26.jpg)
Python: if-else
def imprimir_si(valor): “”” Imprime los parámetros “”” if (valor == “a”): print valor else: print “Parámetro no es ‘a’”
imprimir_si(“a”)
jueves 17 de noviembre de 11
![Page 27: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/27.jpg)
Python: Diccionarios
dicc = { ‘peras’: 1, ‘manzanas’: 2 }print dicc[‘a’]
jueves 17 de noviembre de 11
![Page 28: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/28.jpg)
Python: Diccionarios
dicc = { ‘peras’: 1, ‘manzanas’: 2 }print dicc[‘peras’]dicc[‘naranjas’] = 20print dicc[‘naranjas’]
jueves 17 de noviembre de 11
![Page 29: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/29.jpg)
Python: Diccionarios
dicc = { ‘peras’: 1, ‘manzanas’: 2 }print dicc[‘peras’]dicc[‘naranjas’] = 20print dicc[‘naranjas’]
for fruta in dicc: print dicc[fruta]
jueves 17 de noviembre de 11
![Page 30: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/30.jpg)
Python: TuplasListas inmutables
lista = (1, 20, 300, 4000)print lista[0]
jueves 17 de noviembre de 11
![Page 31: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/31.jpg)
lista = (1, 20, 300, 4000)print lista[0] # Primer elementoprint lista[-1] # Último elemento
Python: TuplasListas inmutables
jueves 17 de noviembre de 11
![Page 32: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/32.jpg)
lista = (1, 20, 300, 4000)print lista[0] # Primer elementoprint lista[-1] # Último elemento
# Subconjuntoslista[:2] # Del 1er al 3er elemento
Python: TuplasListas inmutables
jueves 17 de noviembre de 11
![Page 33: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/33.jpg)
lista = (1, 20, 300, 4000)
# Recorrer tuplafor elemento in lista: print elemento
Python: TuplasListas inmutables
jueves 17 de noviembre de 11
![Page 34: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/34.jpg)
lista = [1, 20, 300, 4000]print lista[0]print lista[-1]
# Añadir elementoslista.append(50000)
Python: ListasListas mutables
jueves 17 de noviembre de 11
![Page 35: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/35.jpg)
Python: Librerías
import libfrom lib import objeto
jueves 17 de noviembre de 11
![Page 36: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/36.jpg)
Python: Objetos
class Fruta: def __init__(self, nombre_fruta): “”” Constructor “”” self.nombre = nombre_fruta
def imprimir_nombre(self): print self.nombre
f = Fruta(“manzana”)f.imprimir_nombre()
jueves 17 de noviembre de 11
![Page 37: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/37.jpg)
Python: FicherosModo lectura
# Abrir ficheroleer = open(“nombre.txt”, “r”)
# Imprimir todas las líneaslinea = leer.readline()while (linea): print linea linea = leer.readline()
# Cerrar ficheroescribir.close()
jueves 17 de noviembre de 11
![Page 38: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/38.jpg)
Python: FicherosModo escritura
# Abrir ficheroescribir = open(“fichero.txt”, “w”)
# Escribir contenidolinea = “”escribir.write(linea)
# Cerrar ficheroescribir.close()
jueves 17 de noviembre de 11
![Page 39: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/39.jpg)
Python: SQLiteCrear/Abrir base de datos
# Abrirconn = sqlite3.connect(“bbdd.sql”)cursor = conn.cursor()
# Cerrarcursor.close()
jueves 17 de noviembre de 11
![Page 40: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/40.jpg)
# Abrirconn = sqlite3.connect(“bbdd.sql”)cursor = conn.cursor()
# Crear tablacursor.execute(“””CREATE TABLE usuarios ( usuario TEXT, twitter TEXT, facebook TEXT, plus TEXT)“””)
# Guardar cambiosconn.commit() cursor.close()
Python: SQLiteCrear tablas
jueves 17 de noviembre de 11
![Page 41: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/41.jpg)
# Abrirconn = sqlite3.connect(“bbdd.sql”)cursor = conn.cursor()
# Crear tablacursor.execute(“””INSERT INTO usuarios VALUES ( ‘rvr’, ‘http://twitter.com/vrruiz’, ‘http://facebook.com/vrruiz/’, ‘https://plus.google.com/115241315008695484224/posts’)“””)
# Guardar cambiosconn.commit()
Python: SQLiteInsertar datos
jueves 17 de noviembre de 11
![Page 42: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/42.jpg)
# Abrirconn = sqlite3.connect(“bbdd.sql”)cursor = conn.cursor()
# Consultar datoscursor.execute(“””SELECT * FROM usuarios“””)for usuario in cursor: print usuario
# Cerrar cursorcursor.close()
Python: SQLiteConsultar tablas
jueves 17 de noviembre de 11
![Page 43: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/43.jpg)
Python: HTTP
import urllib2
# Abrir conexión httppagina = urllib2.open(“http://twitter.com/vrruiz”)
# Leer contenidoscontenidos = pagina.read()print contenidos
# Cerrar conexiónpagina.close()
jueves 17 de noviembre de 11
![Page 44: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/44.jpg)
Python: JSON
from simplejson import json
# Codificar estructura de datos a JSONcodificado = json.dumps({‘usuario’ : ‘rvr’ })print codificado
jueves 17 de noviembre de 11
![Page 45: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/45.jpg)
Python: JSON
from simplejson import json
# Decodificar JSON a estructura de datosdecodificado = json.loads(“{ ‘usuario’ : ‘rvr’ }”)print decodificado
jueves 17 de noviembre de 11
![Page 46: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/46.jpg)
Python: Recursos
• Inmersión en Python
•Documentación oficial: Librerías
jueves 17 de noviembre de 11
![Page 47: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/47.jpg)
¡Gracias por su atención!
jueves 17 de noviembre de 11
![Page 48: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/48.jpg)
Contacto
Víctor R. Ruiztwitter.com/vrruiz · rvr.linotipo.es
> Otras presentaciones disponibles en <http://linotipo.es/
jueves 17 de noviembre de 11
![Page 49: Tecnologías web + Python](https://reader034.vdocumento.com/reader034/viewer/2022052523/5552c248b4c90581158b4877/html5/thumbnails/49.jpg)
Cómo obtener información
en redes socialesVíctor R. Ruiz <[email protected]>
Tenerife, 14-18 de noviembre de 2011
jueves 17 de noviembre de 11