Apresentando Python e
10 motivos pelo qual
devo conhece-lo ?!
Marcel Caraciolo
@marcelcaraciolo
Developer, Cientist, contributor to the Crab recsys project,
works with Python for 6 years, interested at mobile,
education, machine learning and dataaaaa!
Recife, Brazil - http://aimotion.blogspot.com
http://www.slideshare.net/ramalho/python-a-arma-
secreta-do-google
Disclaimer
Alguns slides foram
retirados da apt do
grande Pythonista
Luciano Ramalho
Google em 1998
Disclaimer
Começando pelo
básico...
Começando pelo
básico...
Começando pelo
básico...
print “Hello World”
Mas o que seria
Python ?
Linguagem de Programação interpretada
Fácil de aprender e e altamente produtiva
Multi-Paradigma: Implementa OO,
Funcional e Procedural
Multi-plataforma, Open-source e Divertido!
Mas o que seria
Python ?
lista = [‘laranja’,‘banana’, ‘uva’]
lista.sort()
for item in lista:
print item.capitalize()
Quem usa o
Sim, então é tudo bom
assim é ?
http://en.wikipedia.org/wiki/Expressive_power
Linguagem
Expressiva?
O que isso
significa
na prática?
Linguagem
COBOL
Java
Python
Java
Python tem sido uma parte
importante do Google desde
o início, e continua sendo à
medida que o sistema cresce
e evolui... estamos procurando
mais pessoas com habilidade
nesta linguagem.
Peter Norvig, Google, Inc.
http://aima.cs.berkeley.edu/code.html
lis.py: interpretador
Lisp (Scheme) em
113 linhas de Python,
por Peter Norvig
>>> from lis import repl
>>> repl()
lis.py> (* 7 3)
21
lis.py> (define resposta (* 6 7))
lis.py> resposta
42
lis.py> (define ! (lambda (n) (if (= n 0) 1 (* n (! (- n 1))))))
lis.py> (! 4)
24
lis.py> (! 5)
120
lis.py> (! 197)
10007840558408082122130389497134473659904776124145643156372043719
15587343235626799299914070366966935566947378481954772384977466613
67777918006944650646265409257583733981874437495228286501182991424
47739508657606635346735333579872783783532869428043930552260307311
88238628318646302096556423610922923784067025686796088553504768000
00000000000000000000000000000000000000000000
lis.py> !
<function <lambda> at 0x1004cbd70>
lis.py>
lis.py
Exemplo: relógio gráfico
import Tkinter
from time import strftime
relogio = Tkinter.Label()
relogio.pack()
relogio['font'] = 'Helvetica 120 bold'
relogio['text'] = strftime('%H:%M:%S')
def tictac():
agora = strftime('%H:%M:%S')
if agora != relogio['text']:
relogio['text'] = agora
relogio.after(100, tictac)
tictac()
relogio.mainloop()
Exemplo: cliente Twitter
import sys
import urllib
import json
if len(sys.argv) == 2:
busca = sys.argv[1]
else:
print 'Informe o texto da busca: {0} "texto"'.format(__file__)
sys.exit(1)
url = 'http://search.twitter.com/search.json?q='+busca
resposta = urllib.urlopen(url).read()
documento = json.loads(resposta)
resultados = documento['results']
for resultado in resultados:
print u'{from_user}: {text}n'.format(**resultado)
print '{0} resuldados exibidos'.format(len(resultados))
Como colaborar em Python
Sim, então é tudo bom
assim é ?
1. Python ainda é lento
Sim, então é tudo bom
assim é ?
JIT Compiler em Python
YouTube
Globo.com
Mozilla Firefox Add-Ons
Dropbox
Google App Engine
The Foundry, NUKE
Industrial Light & Magic
Autodesk Maya
Civilization IV
FBI e CIA
brasil.gov.br
brasil.gov.br
Câmara dos Deputados
Integrações com
outras linguagens
Python e C/C++
static PyObject *my_callback = NULL;
static PyObject *
my_set_callback(PyObject *dummy, PyObject *args)
{
PyObject *result = NULL;
PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to new callback */
Py_XDECREF(my_callback); /* Dispose of previous callback */
my_callback = temp; /* Remember new callback */
/* Boilerplate to return "None" */
Py_INCREF(Py_None);
result = Py_None;
}
return result;
}
Você pode extender
Python ou usá-lo em
códigos C/C++
http://docs.python.org/extending/extending.html
Python e .Net
import sys
sys.path.append(r’C:Python25Lib’)
import clr
clr.AddReference(“System.Windows.Forms”)
from System.Windows.Forms import Application,Form
class Hello World(Form):
def __init__(self):
self.Text = ʻHello Worldʼ
self.Name = ʻHello Worldʼ
form = HelloWorld(Form)
Application.Run(Form
http://ironpython.net/
Python e muito mais!
http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html
PyMat - Matlab
http://rpy.sourceforge.net/
http://code.google.com/p/pyswip/
http://appscript.sourceforge.net/
Tem alguém para pedir
socorro.
Pycon US PythonBrasil
PUG-PE
24 hrs ao seu dispor!
http://br.groups.yahoo.com/group/python-brasil/
PUG - PE
Grupo de usuários de Python de
Pernambuco (@pugpe)
http://groups.google.com/group/pug-pe?hl=pt-BR
Tem alguém para pedir
socorro.
http://pythonpeople.znc.com.br/
diveintopython3.ep.io
http://pycursos.com
http://www.youtube.com/watch?v=1Db7r3ujUSQ
Assistentes direto do seu Talk
Conheça o cãocurseiro (@caocurseiro)
Mascote do Atepassar que fala, dorme,
menciona, segue e até RT.
Atepassar
Março 2013
Rápida História
Fundada há 3 anos atrás
3 funcionários, apenas 1 não-era-de-computacao
Trafégo de 1milhão de visitas/mês
250 mil usuários cadastrados, 30k ativos
We	
  s%ll	
  rent	
  hardware,	
  	
  cheaper	
  to	
  upgrade.
EC2	
  -­‐	
  	
  8	
  instances	
  from	
  Micro	
  to	
  Large
	
   (Atepassar	
  Store,	
  Atepassar	
  Network,	
  RecSys,	
  	
  Q&A,	
  Load	
  Balancing)
SES	
  –	
  Quota	
  of	
  	
  575.000	
  e-­‐mails	
  per	
  day	
  sent	
  	
  at	
  90/s
RDS	
  –	
  MySQL	
  –	
  	
  over	
  54	
  million	
  I/O	
  requests	
  -­‐	
  	
  40	
  GB	
  stored.
	
   (	
  For	
  storage)
S3	
  -­‐	
  	
  	
  Over	
  10.0	
  GB	
  and	
  15	
  million	
  requests
	
   (	
  For	
  staKc	
  files	
  )
We	
  use	
  Amazon	
  third-­‐party	
  services	
  such	
  as	
  MongoMachine/MongoHQ	
  NoSQL	
  Storage
Infrastructure
Powered	
  By	
  Python	
  –	
  Django.
We	
  are	
  studying	
  EMR	
  MapReduce	
  to	
  power	
  our	
  recommender	
  system.	
  	
  	
  	
  
	
   Over	
  	
  100.000	
  recommendable	
  items	
  to	
  suggest	
  to	
  our	
  users.
Easy	
  to	
  deploy	
  our	
  apps	
  and	
  install	
  our	
  libraries
	
  	
  	
  	
  	
  	
  	
  Easy	
  to	
  upgrade	
  our	
  infra-­‐structure.
	
   Security	
  and	
  tolerance-­‐fault.
	
   Mix	
  of	
  services	
  available	
  for	
  any	
  big	
  data	
  startup	
  around	
  the	
  world.
	
  
Technology
e aí preparado ?
Você pode escolher
ficar no vermelho...
Você pode escolher
ficar no vermelho...
Ou ser “Livre”
Marcel Caraciolo
@marcelcaraciolo
marcel@atepassar.com ou
marcel@caraciolo.com.br
contato
Marcel Caraciolo
@marcelcaraciolo
marcel@atepassar.com ou
marcel@caraciolo.com.br
contato
Apresentando Python e
10 motivos pelo qual
devo conhece-lo ?!
Marcel Caraciolo
@marcelcaraciolo
Developer, Cientist, contributor to the Crab recsys project,
works with Python for 6 years, interested at mobile,
education, machine learning and dataaaaa!
Recife, Brazil - http://aimotion.blogspot.com

Python e 10 motivos por que devo conhece-la ?

  • 1.
    Apresentando Python e 10motivos pelo qual devo conhece-lo ?! Marcel Caraciolo @marcelcaraciolo Developer, Cientist, contributor to the Crab recsys project, works with Python for 6 years, interested at mobile, education, machine learning and dataaaaa! Recife, Brazil - http://aimotion.blogspot.com
  • 2.
  • 3.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
    Mas o queseria Python ? Linguagem de Programação interpretada Fácil de aprender e e altamente produtiva Multi-Paradigma: Implementa OO, Funcional e Procedural Multi-plataforma, Open-source e Divertido!
  • 11.
    Mas o queseria Python ? lista = [‘laranja’,‘banana’, ‘uva’] lista.sort() for item in lista: print item.capitalize()
  • 12.
  • 13.
    Sim, então étudo bom assim é ? http://en.wikipedia.org/wiki/Expressive_power
  • 14.
  • 15.
  • 16.
  • 17.
    Python tem sidouma parte importante do Google desde o início, e continua sendo à medida que o sistema cresce e evolui... estamos procurando mais pessoas com habilidade nesta linguagem. Peter Norvig, Google, Inc.
  • 18.
  • 19.
    lis.py: interpretador Lisp (Scheme)em 113 linhas de Python, por Peter Norvig
  • 20.
    >>> from lisimport repl >>> repl() lis.py> (* 7 3) 21 lis.py> (define resposta (* 6 7)) lis.py> resposta 42 lis.py> (define ! (lambda (n) (if (= n 0) 1 (* n (! (- n 1)))))) lis.py> (! 4) 24 lis.py> (! 5) 120 lis.py> (! 197) 10007840558408082122130389497134473659904776124145643156372043719 15587343235626799299914070366966935566947378481954772384977466613 67777918006944650646265409257583733981874437495228286501182991424 47739508657606635346735333579872783783532869428043930552260307311 88238628318646302096556423610922923784067025686796088553504768000 00000000000000000000000000000000000000000000 lis.py> ! <function <lambda> at 0x1004cbd70> lis.py> lis.py
  • 21.
    Exemplo: relógio gráfico importTkinter from time import strftime relogio = Tkinter.Label() relogio.pack() relogio['font'] = 'Helvetica 120 bold' relogio['text'] = strftime('%H:%M:%S') def tictac(): agora = strftime('%H:%M:%S') if agora != relogio['text']: relogio['text'] = agora relogio.after(100, tictac) tictac() relogio.mainloop()
  • 22.
    Exemplo: cliente Twitter importsys import urllib import json if len(sys.argv) == 2: busca = sys.argv[1] else: print 'Informe o texto da busca: {0} "texto"'.format(__file__) sys.exit(1) url = 'http://search.twitter.com/search.json?q='+busca resposta = urllib.urlopen(url).read() documento = json.loads(resposta) resultados = documento['results'] for resultado in resultados: print u'{from_user}: {text}n'.format(**resultado) print '{0} resuldados exibidos'.format(len(resultados))
  • 27.
  • 28.
    Sim, então étudo bom assim é ? 1. Python ainda é lento
  • 29.
    Sim, então étudo bom assim é ? JIT Compiler em Python
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 44.
  • 45.
    Python e C/C++ staticPyObject *my_callback = NULL; static PyObject * my_set_callback(PyObject *dummy, PyObject *args) { PyObject *result = NULL; PyObject *temp; if (PyArg_ParseTuple(args, "O:set_callback", &temp)) { if (!PyCallable_Check(temp)) { PyErr_SetString(PyExc_TypeError, "parameter must be callable"); return NULL; } Py_XINCREF(temp); /* Add a reference to new callback */ Py_XDECREF(my_callback); /* Dispose of previous callback */ my_callback = temp; /* Remember new callback */ /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; } return result; } Você pode extender Python ou usá-lo em códigos C/C++ http://docs.python.org/extending/extending.html
  • 46.
    Python e .Net importsys sys.path.append(r’C:Python25Lib’) import clr clr.AddReference(“System.Windows.Forms”) from System.Windows.Forms import Application,Form class Hello World(Form): def __init__(self): self.Text = ʻHello Worldʼ self.Name = ʻHello Worldʼ form = HelloWorld(Form) Application.Run(Form http://ironpython.net/
  • 47.
    Python e muitomais! http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html PyMat - Matlab http://rpy.sourceforge.net/ http://code.google.com/p/pyswip/ http://appscript.sourceforge.net/
  • 48.
    Tem alguém parapedir socorro. Pycon US PythonBrasil PUG-PE
  • 49.
    24 hrs aoseu dispor! http://br.groups.yahoo.com/group/python-brasil/
  • 50.
    PUG - PE Grupode usuários de Python de Pernambuco (@pugpe) http://groups.google.com/group/pug-pe?hl=pt-BR
  • 51.
    Tem alguém parapedir socorro. http://pythonpeople.znc.com.br/
  • 53.
  • 54.
  • 55.
  • 56.
    Assistentes direto doseu Talk Conheça o cãocurseiro (@caocurseiro) Mascote do Atepassar que fala, dorme, menciona, segue e até RT.
  • 57.
  • 58.
    Rápida História Fundada há3 anos atrás 3 funcionários, apenas 1 não-era-de-computacao Trafégo de 1milhão de visitas/mês 250 mil usuários cadastrados, 30k ativos
  • 59.
    We  s%ll  rent  hardware,    cheaper  to  upgrade. EC2  -­‐    8  instances  from  Micro  to  Large   (Atepassar  Store,  Atepassar  Network,  RecSys,    Q&A,  Load  Balancing) SES  –  Quota  of    575.000  e-­‐mails  per  day  sent    at  90/s RDS  –  MySQL  –    over  54  million  I/O  requests  -­‐    40  GB  stored.   (  For  storage) S3  -­‐      Over  10.0  GB  and  15  million  requests   (  For  staKc  files  ) We  use  Amazon  third-­‐party  services  such  as  MongoMachine/MongoHQ  NoSQL  Storage Infrastructure
  • 60.
    Powered  By  Python  –  Django. We  are  studying  EMR  MapReduce  to  power  our  recommender  system.           Over    100.000  recommendable  items  to  suggest  to  our  users. Easy  to  deploy  our  apps  and  install  our  libraries              Easy  to  upgrade  our  infra-­‐structure.   Security  and  tolerance-­‐fault.   Mix  of  services  available  for  any  big  data  startup  around  the  world.   Technology
  • 62.
  • 63.
  • 64.
  • 66.
  • 67.
  • 68.
  • 69.
    Apresentando Python e 10motivos pelo qual devo conhece-lo ?! Marcel Caraciolo @marcelcaraciolo Developer, Cientist, contributor to the Crab recsys project, works with Python for 6 years, interested at mobile, education, machine learning and dataaaaa! Recife, Brazil - http://aimotion.blogspot.com