2. Motivacin
4. Python es?
5. Diseado para las personas
6. Menos cdigo
x,y,z = 2,'hola',pow
print z 7. Menos cdigo
for i in range(5): if i == 3: print "i es 3" 8. Interactivo de fbrica
9. Sirve como calculadora, shell o ambiente de pruebas. $python $ipython 10. Todo es un objeto
>>> "hola".upper() 'HOLA' >>> int(1).__add__(1) 2 11. Estructuras dinmicas
l = [3,'cuatro',5j,[0x6a,0x6b]] d = {fpalm:[impulsivo,distraido, extravagante]} 12. Listas y comprensivas
>>> li = ['tel','cite','cnti','a'] >>> [i for i in li if 'te' in i] ['tel', 'cite'] 13. Viene con pilas includas
import smtplib server = smtplib.SMTP('localhost') server.sendmail('x@z','y@z','hola') server.quit() 14. Autodocumentado
>>> def tome_pim(x): ...""" y haga pum! """ ...return "pum(%s)" % x >>> tome_pim.__doc__ ' y haga pum! ' 15. Introspectivo
[(met, met.__doc__) for met in dir(math) if not(callable(getattr(math,met)))] 16. Captura de Errores
17. Captura de Errores Traceback (most recent call last): File "simredes.py", line 229, in lee_nom_arch() File "simredes.py", line 90, in lee_nom_arch a_entrada = open(nombre_e,'r') IOError: [Errno 2] No such file or directory: '.DEF' 18. Habla web
import BaseHTTPServer httpd =
BaseHTTPServer.HTTPServer(('',8000),
BaseHTTPServer.BaseHTTPRequestHandler) httpd.serve_forever() 19.
Python calculadora >>> (1+2j)/(1+1j) (1.5+0.5j)
>>> from scipy.integrate import quad >>> import
math >>> quad(lambda x: math.exp(-x), 0, 4.5)
(0.98889100346175751, 1.0978895608879186e-14) 20. Thumbnails con
PIL import os, sys, Image size = 128, 128 for infile in
sys.argv[1:]: outfile = os.path.splitext(infile)[0] +
"-thumbnail.jpg" try: im = Image.open(infile) im.thumbnail(size)
im.save(outfile, "JPEG") except IOError: print "no se puede con",
infile 21. Tomar notas con Synoptic $ apt-get install
python-setuptools $ sudo easy_install synoptic $ synoptic flisol
serving at http://127.0.0.1:7331/... 22. Jugar con gedit def
clean_moin(window): doc = window.get_active_document() flag = 0
doc.replace_all(' `',' {{{ ',flag) doc.replace_all('` ',' }}}
',flag) doc.replace_all('
',' ',flag) 23. Diagramas con pygraphviz from pygraphviz import *
fromrandom import randint A = AGraph() for i in range(16):
A.add_edge(randint(0,15),i) n = A.get_node(i) print A.string()
A.draw("star.png",prog="circo") 24. Conclusiones
25. No garantiza la felicidad pero te deja en la vuelta de la esquina...