Python:
Cabe no seu bolso,
no seu micro,
no seu cérebro
Rodrigo Dias Arruda Senra
rsenra@acm.org
Infnet 2015
Apenas um rapaz latino americano...
• Engenheiro de Software 

• GPr Sistemas (11 anos)
• HI Tecnologia (5 anos)

• Professor Universitário - PUC-Campinas (2 anos)
• Especialista - globo.com (2 anos)
• Cientista Pesquisador - EMC2
• Engenheiro de Computação 

Grad-MSc-PhD IC-Unicamp
• Entusiasta de FLOSS

(atuante na comunidade Python desde 2000)
Quem está aí ?
• Estudantes ?

• Profissionais ?

• Professores ?

• Palestrantes ?

• Pythonistas ?
Vamos falar do quê ?
• O Graal do desenvolvedor ?

• Escolhendo uma linguagem

• Contextualizando Python 

• Vocabulário Ofidiglota
O Graal do Desenvolvedor
• Facilidade
• Legibilidade
• Estabilidade
• Portabilidade
• Interoperabilidade
• Extensibilidade
• Escalabilidade
O Graal do Desenvolvedor
• Rapidez no Ciclo de
Desenvolvimento
• Facilidade
• Legibilidade
• Estabilidade
• Portabilidade
• Interoperabilidade
• Extensibilidade
• Customização
• Escalabilidade
• Segurança
O Graal do Desenvolvedor
A eterna busca pela
ferramenta perfeita
40
Plankalkü
Transistor
50
Fortran
LISP
Harddisk
Circuito
Integrado
60
COBOL
SIMULA
BASIC
LOGO
ITS
OS360
MULTICS
Mouse
Interrupções
Virt.Mem
ARPANET
RS-232
70
Pascal
C
Smalltalk
Prolog
UNIX
CP/M
VMS
Floppy
Micro-
processador
PONG
TCP/IP
Ethernet
80
Ada
C++
Perl
SQL
LISA
Macintosh
UNIX
MS-DOS
Windows
1.0-2.0
OS/2
MINIX
AIX
HPUX
SCO
GNU
RISC
90
Javascript
Python
Java
PHP
BeOS
Linux
Solaris
Windows
2.0 - 98
OpenBSD
ISA
WWW
2000
Scala
C#
Mac OSX
Windows
ME
2000
XP
Vista
7
Go
Linux
Julia
A verdade dói...
# Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
A verdade dói...
# Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
FORTRAN --"the infantile
disorder"--, by now nearly
20 years old, is hopelessly
inadequate for whatever
computer application
you have in mind today:
it is now too clumsy, too
risky, and too expensive to
use
A verdade dói...
# Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
PL/1 --"the fatal
disease"-- belongs
more to the
problem set than to
the solution set
A verdade dói...
# Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
It is practically impossible
to teach good
programming to students
that have had a prior
exposure to BASIC: as
potential programmers
they are mentally
mutilated beyond hope of
regeneration
A verdade dói...
# Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
The use of COBOL
cripples the mind; its
teaching should,
therefore, be regarded as
a criminal offence
Truth lies on statistics!
Top 10 - SourceForge
http://githut.info/
Last data update: Fri Jul 24 20:03:26 BRT 2015
http://www.langpop.com
Yahoo Search, Craigslist, Ohloh, Google Code, Freshmeat, Delicious, Powells
http://sogrady-media.redmonk.com/sogrady/files/2015/07/lang-rank-615-wm.png
Segurança Fonte: http://nvd.nist.gov/nvd.cfm
Python 91
Ruby 109
JS 209
Java 613
C 1559
PHP 2732
http://benchmarksgame.alioth.debian.org/u64q/which-programs-are-fastest.html
Duelo de linguagens
Duelo de linguagens
import java.io.*;
import java.util.*;
import java.text.*;
public class sumcol {
public static void main(String[] args) {
int count = 0;
String line;
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
while ((line = in.readLine()) != null) {
count = count + Integer.parseInt(line);
}
} catch (IOException e) { }
System.out.println(Integer.toString(count));
Javausing System;
class App {
public static int Main(String[] args) {
int count = 0;
for (String line = Console.In.ReadLine();
line != null;
line = Console.In.ReadLine())
{ count += System.Convert.ToInt32(line); }
Console.WriteLine(count.ToString());
return(0);
}
C#import sys
count = 0
while 1:
line = sys.stdin.readline().strip()
if not line:
break
count += int(line)
print count
Pythonimport sys, itertools
print sum(itertools.imap(int, sys.stdin))
Python
Who is using Python ?
Fernando Perez, lead PI at BIDS and creator of IPython, demonstrates brain imaging analyses
performed using the IPython Notebook, an interactive web-based computational environment.
credit: Peg Skorpinski
http://i0.wp.com/sciencereview.berkeley.edu/wp-content/uploads/2014/04/spring_2014_azam_05.jpg
Python é ...
• propósito geral

• foco em produtividade do desenvolvedor

• multi-plataforma e multi-paradigma

• pilhas incluídas

• floss software

• fácil de extender e embutir

• madura (criada em1989, liberada ao público 1991)
Interoperabiilidade
✴ Jython (Python implementado em Java)

✴ CPython (onde existir compilador C ISO/IEC 9899:1990) 

✴ IronPython (implementado em C# pela M$)

✴ PyPy (Python implementado em... Python)

✴ Py4J (ponte entre CPython e JVM)

✴ Python for .NET [Brian Lloyd]

✴ Win32all [Mark Hammond] (adeus VBA!)

✴ PyObjC (Mac OSX middleware)

✴ Python for Delphi [Morgan Marat]

✴ LunaticPython [Gustavo Niemeyer] 

✴ Ruby/Python (importar módulos Python em Ruby)

✴ Python + Fortran
Hora da Demo
Dá tempo de ver
o Python em ação ?
É possível ?
Seria pedir muito ?
Pygame
Python no celular S60
Bancos de Dados
from psycopg import *
o = connect(“ dbname=teste user=fulano” )
c = o.cursor()
c.execute(“ SELECT * FROM nome_da_tabela” )
row = c.fetchone()
print row
x = [ ('valor_1', 'fulano', 0), ('valor_2', 'beltrano', 5),
('valor_3', 'ciclano', 15)]
c.executemany(" " " INSERT INTO outra_tabela
VALUES (%s, %s, %s)""", x)
c.commit()
Networking
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
from time import asctime
class TimeServer(Protocol):
def dataReceived(self, data):
self.transport.write(asctime())
def main():
f = Factory()
f.protocol = TimeServer
reactor.listenTCP(8000, f)
reactor.run()
main()
Web Services
from SOAPpy import SOAPProxy
from SOAPpy import Types
google = SOAPProxy( 'http://api.google.com/search/beta2',
'urn:GoogleSearch')
results = google.doGetCachedPage('Pd6ke...ArQoX' ,
'www.owls.org')
of = open('cached_page_response.html', 'w')
of.write(results)
of.close()
SciPy
import view
from Numeric import *
x = arange(-3, 6, .04)
y = arange(-12, 12, .08)
y = sin(y)*exp(-y*y/18.0)
z = x * y[:,NewAxis]
view.view(z)
Apps
Referências
! http://python.org
! http://www.pythonbrasil.com.br
! http://associacao.pythonbrasil.org
! http://showmedo.com
Referências
! Fluent Python: Luciano Ramalho (O’Reilly)

! Python in a Nutshell: Alex Martelli (O'Reilly)

! Python Cookbook: Alex Martelli, David Ascher (O'Reilly)

! Learning Python for Interactive Computing and Data
Visualisation: Cyrille Rossant (Packt)
Conclusão
• Ágil, madura e moderna
• Fácil aprendizado
• Comunidade Ativa
• Fartura de documentação
• Divertida ;o)
Obrigado a todos
pela atenção.
Rodrigo Dias Arruda Senra
http://rodrigo.senra.nom.br
rodsenra@gmail.com
@rodsenra
As opiniões e conclusões expressas nesta apresentação são de exclusiva responsabilidade de Rodrigo Senra.
Não é necessário requisitar permissão do autor para o uso de partes ou do todo desta apresentação, desde que não sejam feitas
alterações no conteúdo reutilizado e que esta nota esteja presente na íntegra no material resultante.
Imagens e referências para outros trabalhos nesta apresentação permanecem propriedade daqueles que detêm seus direitos de
copyright. Agradecimento especial a Ana Oliveira e Diego Salomone que contribuíram com alguns slides de suas apresentações sobre
o mesmo tema.

Python: Cabe no seu bolso, no seu micro, no seu cérebro.

  • 1.
    Python: Cabe no seubolso, no seu micro, no seu cérebro Rodrigo Dias Arruda Senra rsenra@acm.org Infnet 2015
  • 2.
    Apenas um rapazlatino americano... • Engenheiro de Software • GPr Sistemas (11 anos) • HI Tecnologia (5 anos) • Professor Universitário - PUC-Campinas (2 anos) • Especialista - globo.com (2 anos) • Cientista Pesquisador - EMC2 • Engenheiro de Computação Grad-MSc-PhD IC-Unicamp • Entusiasta de FLOSS (atuante na comunidade Python desde 2000)
  • 3.
    Quem está aí? • Estudantes ? • Profissionais ? • Professores ? • Palestrantes ? • Pythonistas ?
  • 4.
    Vamos falar doquê ? • O Graal do desenvolvedor ? • Escolhendo uma linguagem • Contextualizando Python • Vocabulário Ofidiglota
  • 5.
    O Graal doDesenvolvedor
  • 6.
    • Facilidade • Legibilidade •Estabilidade • Portabilidade • Interoperabilidade • Extensibilidade • Escalabilidade O Graal do Desenvolvedor
  • 7.
    • Rapidez noCiclo de Desenvolvimento • Facilidade • Legibilidade • Estabilidade • Portabilidade • Interoperabilidade • Extensibilidade • Customização • Escalabilidade • Segurança O Graal do Desenvolvedor
  • 8.
    A eterna buscapela ferramenta perfeita
  • 10.
  • 11.
    A verdade dói... #Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm
  • 12.
    A verdade dói... #Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm FORTRAN --"the infantile disorder"--, by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expensive to use
  • 13.
    A verdade dói... #Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm PL/1 --"the fatal disease"-- belongs more to the problem set than to the solution set
  • 14.
    A verdade dói... #Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration
  • 15.
    A verdade dói... #Edsger W.Dijkstra, 18 Junho 1975 http://www.cbi.umn.edu/inv/burros/ewd498.htm The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence
  • 16.
    Truth lies onstatistics!
  • 18.
    Top 10 -SourceForge
  • 19.
  • 20.
    Last data update:Fri Jul 24 20:03:26 BRT 2015 http://www.langpop.com Yahoo Search, Craigslist, Ohloh, Google Code, Freshmeat, Delicious, Powells
  • 21.
  • 23.
    Segurança Fonte: http://nvd.nist.gov/nvd.cfm Python91 Ruby 109 JS 209 Java 613 C 1559 PHP 2732
  • 24.
  • 25.
  • 26.
  • 27.
    import java.io.*; import java.util.*; importjava.text.*; public class sumcol { public static void main(String[] args) { int count = 0; String line; try { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); while ((line = in.readLine()) != null) { count = count + Integer.parseInt(line); } } catch (IOException e) { } System.out.println(Integer.toString(count)); Javausing System; class App { public static int Main(String[] args) { int count = 0; for (String line = Console.In.ReadLine(); line != null; line = Console.In.ReadLine()) { count += System.Convert.ToInt32(line); } Console.WriteLine(count.ToString()); return(0); } C#import sys count = 0 while 1: line = sys.stdin.readline().strip() if not line: break count += int(line) print count Pythonimport sys, itertools print sum(itertools.imap(int, sys.stdin)) Python
  • 28.
    Who is usingPython ?
  • 30.
    Fernando Perez, leadPI at BIDS and creator of IPython, demonstrates brain imaging analyses performed using the IPython Notebook, an interactive web-based computational environment. credit: Peg Skorpinski
  • 31.
  • 35.
    Python é ... •propósito geral • foco em produtividade do desenvolvedor • multi-plataforma e multi-paradigma • pilhas incluídas • floss software • fácil de extender e embutir • madura (criada em1989, liberada ao público 1991)
  • 36.
    Interoperabiilidade ✴ Jython (Pythonimplementado em Java) ✴ CPython (onde existir compilador C ISO/IEC 9899:1990) ✴ IronPython (implementado em C# pela M$) ✴ PyPy (Python implementado em... Python) ✴ Py4J (ponte entre CPython e JVM) ✴ Python for .NET [Brian Lloyd] ✴ Win32all [Mark Hammond] (adeus VBA!) ✴ PyObjC (Mac OSX middleware) ✴ Python for Delphi [Morgan Marat] ✴ LunaticPython [Gustavo Niemeyer] ✴ Ruby/Python (importar módulos Python em Ruby) ✴ Python + Fortran
  • 37.
    Hora da Demo Dátempo de ver o Python em ação ? É possível ? Seria pedir muito ?
  • 38.
  • 39.
  • 40.
    Bancos de Dados frompsycopg import * o = connect(“ dbname=teste user=fulano” ) c = o.cursor() c.execute(“ SELECT * FROM nome_da_tabela” ) row = c.fetchone() print row x = [ ('valor_1', 'fulano', 0), ('valor_2', 'beltrano', 5), ('valor_3', 'ciclano', 15)] c.executemany(" " " INSERT INTO outra_tabela VALUES (%s, %s, %s)""", x) c.commit()
  • 41.
    Networking from twisted.internet.protocol importProtocol, Factory from twisted.internet import reactor from time import asctime class TimeServer(Protocol): def dataReceived(self, data): self.transport.write(asctime()) def main(): f = Factory() f.protocol = TimeServer reactor.listenTCP(8000, f) reactor.run() main()
  • 42.
    Web Services from SOAPpyimport SOAPProxy from SOAPpy import Types google = SOAPProxy( 'http://api.google.com/search/beta2', 'urn:GoogleSearch') results = google.doGetCachedPage('Pd6ke...ArQoX' , 'www.owls.org') of = open('cached_page_response.html', 'w') of.write(results) of.close()
  • 43.
    SciPy import view from Numericimport * x = arange(-3, 6, .04) y = arange(-12, 12, .08) y = sin(y)*exp(-y*y/18.0) z = x * y[:,NewAxis] view.view(z)
  • 44.
  • 45.
    Referências ! http://python.org ! http://www.pythonbrasil.com.br !http://associacao.pythonbrasil.org ! http://showmedo.com
  • 46.
    Referências ! Fluent Python:Luciano Ramalho (O’Reilly) ! Python in a Nutshell: Alex Martelli (O'Reilly) ! Python Cookbook: Alex Martelli, David Ascher (O'Reilly) ! Learning Python for Interactive Computing and Data Visualisation: Cyrille Rossant (Packt)
  • 47.
    Conclusão • Ágil, madurae moderna • Fácil aprendizado • Comunidade Ativa • Fartura de documentação • Divertida ;o)
  • 49.
    Obrigado a todos pelaatenção. Rodrigo Dias Arruda Senra http://rodrigo.senra.nom.br rodsenra@gmail.com @rodsenra As opiniões e conclusões expressas nesta apresentação são de exclusiva responsabilidade de Rodrigo Senra. Não é necessário requisitar permissão do autor para o uso de partes ou do todo desta apresentação, desde que não sejam feitas alterações no conteúdo reutilizado e que esta nota esteja presente na íntegra no material resultante. Imagens e referências para outros trabalhos nesta apresentação permanecem propriedade daqueles que detêm seus direitos de copyright. Agradecimento especial a Ana Oliveira e Diego Salomone que contribuíram com alguns slides de suas apresentações sobre o mesmo tema.