SlideShare a Scribd company logo
python3
@andrewsmedina
‣   o que os outros pensam...




globo
 .com
‣   o que eu penso...




globo
 .com
‣   o que minha mãe pensa...




globo
 .com
‣   como realmente é!




globo
 .com
python 2
‣   pep8              ‣   generators
        ‣   zen of python     ‣   iterators
        ‣   decorators        ‣   comprehension
        ‣   descriptors       ‣   abstract
        ‣   metaclass         ‣   magic methods
        ‣   context manager
        ‣   subproccess
        ‣   multiproccess

globo
 .com
mas...
‣   unicode
        ‣   classes new x old style
        ‣   // vs /
        ‣   print vs print()
        ‣   int vs long
        ‣   urllib, urllib2, urlparse
        ‣   xmlrpclib, DocXMLRPCServer, SimpleXMLRPCServer



globo
 .com
:(
python3
        ‣   pep8
        ‣   zen of python
        ‣   generators
        ‣   iterators
        ‣   objetos




globo
 .com
python3.0
           2008..




globo
 .com
python3.0
        ‣   pip, distribute não funcionava no python3
        ‣   2to3 não foi suficiente




globo
 .com
python3.3
        ‣   pip, distribute
        ‣   venv nativo
        ‣   2to3, 3to2, six
        ‣   várias features já funcionam no python2.7




globo
 .com
python3 no python2
divisão (python2)
         >>> 4 / 2
         2
         >>> 3 / 2
         1



globo
 .com
divisão (python3)
         >>> 3 / 2
         1.5




globo
 .com
divisão (python2)
         from __future__ import division
         >>> 3 / 2
         1.5




globo
 .com
divisão (python2)
         from __future__ import division
         >>> 3 // 2
         1




globo
 .com
string.format()
        “{0} - {1}”.format(“andrews”, 19)
        “{name} - {idade}”.format(name=”andrews”, idade=19)



globo
 .com
comprehension
        {x for x in [1,2,3,3]}




globo
 .com
comprehension
        {key.upper(): value for key, value in d.items()}




globo
 .com
generators


globo
 .com
classes abstratas


globo
 .com
multiprocessing


globo
 .com
bytes e strings
        bytes para transferência
        string para representação



globo
 .com
bytes e strings
        bytes (python3) == str (python2)
        string (python3 == bytes (python2)



globo
 .com
bytes e strings (python2)
        u"andrews " + b"medina"
        u”andrews medina”



globo
 .com
bytes e strings (python3)
        >>> u"andrews " + b"medina"
        Traceback (most recent call last):
         File "<stdin>", line 1, in <module>
        TypeError: Can't convert 'bytes' object to str implicitly


globo
 .com
strings para bytes
        u"andrews ".encode(“utf-8”) + b"medina"




globo
 .com
bytes para strings
        u"andrews " + b"medina".decode(“utf-8”)




globo
 .com
print
        objeto
        novos parâmetros (sep, end, file, flush)



globo
 .com
print (python2)
        >>> help(print)
         File "<stdin>", line 1
           help(print)
                  ^
        SyntaxError: invalid syntax


globo
 .com
print (python3)
        >>> help(print)



globo
 .com
print (python2)
        >>> from __future__ import print_function
        >>> help(print)


globo
 .com
print (python2)
        >>> print(", ".join(["banana", "batata"]))
        banana, batata


globo
 .com
print (python3)
        >>> alimentos = ["banana", "batata"]
        >>> print(*alimentos, sep=", ")
        banana, batata


globo
 .com
print (python3)
        from StringIO import StringIO
        out = StringIO()
        >>> print("ble", file=out)
        >>> out.getvalue()
        'blen'


globo
 .com
range, zip, map, filter
        retornam iterators




globo
 .com
range, zip, map, filter
        lista = list(range(10))




globo
 .com
range, zip, map, filter
        for item in range(10):
           print item




globo
 .com
expections
        except IOError as e:




globo
 .com
class Class:
        new style por padrão




globo
 .com
int
        int = long




globo
 .com
novidades
annotations
        adiciona meta dados em uma função




globo
 .com
annotations
        def hello(name: str, age: int) -> int:
           print(name, age)




globo
 .com
annotations
        >>> hello.__annotations__
        {'return': <class 'int'>, 'name': <class 'str'>, 'age': <class 'int'>}




globo
 .com
annotations
        >>> hello("ble", "ble")
        ble ble




globo
 .com
io
        io.FileIO
        io.StringIO
        io.BufferIO



globo
 .com
concurrent.future
        paralelismo




globo
 .com
concurrent.future
        interface Executor




globo
 .com
concurrent.future
        from concurrent.futures import ThreadPoolExecutor

        with ThreadPoolExecutor(max_workers=1) as executor:
           future = executor.submit(pow, 323, 1235)
           print(future.result())

globo
 .com
concurrent.future
        from concurrent.futures import ProcessPoolExecutor

        with ProcessPoolExecutor(max_workers=4) as executor:
           future = executor.submit(pow, 323, 1235)
           print(future.result())

globo
 .com
functools.lru_cache
        memoização nativa




globo
 .com
functools.lru_cache
        from functools import lru_cache

        @lru_cache(maxsize=None)
        def fib(n):
           if n < 2:
               return n
           return fib(n-1) + fib(n-2)


globo
 .com
venv (virtualenv)


globo
 .com
unittest(2)


globo
 .com
unittest.mock


globo
 .com
pep 420
        Implicit Namespace Packages




globo
 .com
como portar
apenas python3


globo
 .com
branches diferentes
        manter dois projetos :(




globo
 .com
2to3
        convertor automágico




globo
 .com
2to3
        print “ble” -> print(ble)
        except Exception, e -> except Exception as e




globo
 .com
2to3
        2to3=true #distribute




globo
 .com
3to2


globo
 .com
mesma base de código
        tratamento de excessões




globo
 .com
six
        :)




globo
 .com
leitura
        ‣   http://python3porting.com/
        ‣   http://docs.python.org/3/
        ‣   http://getpython3.com/diveintopython3/




globo
 .com
perguntas?

More Related Content

PDF
Diving into byte code optimization in python
PDF
Let's golang
PDF
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
PDF
Tcl2012 8.6 Changes
PDF
Exploring slides
ODP
Naïveté vs. Experience
PDF
Are we ready to Go?
PPT
Python легко и просто. Красиво решаем повседневные задачи
Diving into byte code optimization in python
Let's golang
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Tcl2012 8.6 Changes
Exploring slides
Naïveté vs. Experience
Are we ready to Go?
Python легко и просто. Красиво решаем повседневные задачи

What's hot (20)

PDF
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
ODP
An Intro to Python in 30 minutes
PDF
Golang勉強会
PPTX
Hacking Go Compiler Internals / GoCon 2014 Autumn
PDF
Coding in GO - GDG SL - NSBM
PPT
Euro python2011 High Performance Python
PDF
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
ODP
OpenGurukul : Language : Python
PPT
Functional Pe(a)rls version 2
PDF
C++の話(本当にあった怖い話)
PDF
ClojureScript loves React, DomCode May 26 2015
PDF
Go ahead, make my day
PDF
Full Stack Clojure
PDF
Snakes for Camels
PDF
TypeScript Introduction
PPTX
Dts x dicoding #2 memulai pemrograman kotlin
ODP
OpenGurukul : Language : PHP
KEY
Beauty and Power of Go
PDF
ClojureScript for the web
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
The Ring programming language version 1.5.3 book - Part 25 of 184
An Intro to Python in 30 minutes
Golang勉強会
Hacking Go Compiler Internals / GoCon 2014 Autumn
Coding in GO - GDG SL - NSBM
Euro python2011 High Performance Python
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
OpenGurukul : Language : Python
Functional Pe(a)rls version 2
C++の話(本当にあった怖い話)
ClojureScript loves React, DomCode May 26 2015
Go ahead, make my day
Full Stack Clojure
Snakes for Camels
TypeScript Introduction
Dts x dicoding #2 memulai pemrograman kotlin
OpenGurukul : Language : PHP
Beauty and Power of Go
ClojureScript for the web
Ad

Viewers also liked (6)

PDF
JSON Schema: Valide e navegue entre suas APIS
KEY
Design de código: princípios e práticas para ter um código sustentável
PDF
CEJS 2016 - Please learn that shit
KEY
Escalando aplicações web
PDF
256 Shades of R, G and B
PDF
React Native na globo.com
JSON Schema: Valide e navegue entre suas APIS
Design de código: princípios e práticas para ter um código sustentável
CEJS 2016 - Please learn that shit
Escalando aplicações web
256 Shades of R, G and B
React Native na globo.com
Ad

Similar to Python 3 (20)

KEY
Python 3 - tutorial
PPT
Python Evolution
PPTX
PyCourse - Self driving python course
PDF
Python for PHP developers
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PPTX
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PDF
What is python
PDF
Learning Python from Data
PDF
Lecture1_cis4930.pdf
PDF
Pyhton-1a-Basics.pdf
PPT
Python Training v2
PDF
Python于Web 2.0网站的应用 - QCon Beijing 2010
PPT
Python
PPTX
Python-Yesterday Today Tomorrow(What's new?)
TXT
vvvvReadme
PDF
Python basics
PDF
Python basics
KEY
State of Python (2010)
PDF
Intermediate python
Python 3 - tutorial
Python Evolution
PyCourse - Self driving python course
Python for PHP developers
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
What is python
Learning Python from Data
Lecture1_cis4930.pdf
Pyhton-1a-Basics.pdf
Python Training v2
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python
Python-Yesterday Today Tomorrow(What's new?)
vvvvReadme
Python basics
Python basics
State of Python (2010)
Intermediate python

More from Andrews Medina (9)

KEY
testando interfaces web
KEY
desenvolvendo jogos para android
KEY
técnica de desenvolvimento de jogos para web
KEY
realtime - passado, presente e futuro
KEY
Haskell para pythonistas
PDF
animações e jogos além do canvas
KEY
escalando aplicações django
PDF
Desenvolvimento de Jogos em Python
PDF
Django Show
testando interfaces web
desenvolvendo jogos para android
técnica de desenvolvimento de jogos para web
realtime - passado, presente e futuro
Haskell para pythonistas
animações e jogos além do canvas
escalando aplicações django
Desenvolvimento de Jogos em Python
Django Show

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Machine Learning_overview_presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Big Data Technologies - Introduction.pptx
Machine Learning_overview_presentation.pptx
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Python 3

  • 2. o que os outros pensam... globo .com
  • 3. o que eu penso... globo .com
  • 4. o que minha mãe pensa... globo .com
  • 5. como realmente é! globo .com
  • 7. pep8 ‣ generators ‣ zen of python ‣ iterators ‣ decorators ‣ comprehension ‣ descriptors ‣ abstract ‣ metaclass ‣ magic methods ‣ context manager ‣ subproccess ‣ multiproccess globo .com
  • 9. unicode ‣ classes new x old style ‣ // vs / ‣ print vs print() ‣ int vs long ‣ urllib, urllib2, urlparse ‣ xmlrpclib, DocXMLRPCServer, SimpleXMLRPCServer globo .com
  • 10. :(
  • 11. python3 ‣ pep8 ‣ zen of python ‣ generators ‣ iterators ‣ objetos globo .com
  • 12. python3.0 2008.. globo .com
  • 13. python3.0 ‣ pip, distribute não funcionava no python3 ‣ 2to3 não foi suficiente globo .com
  • 14. python3.3 ‣ pip, distribute ‣ venv nativo ‣ 2to3, 3to2, six ‣ várias features já funcionam no python2.7 globo .com
  • 16. divisão (python2) >>> 4 / 2 2 >>> 3 / 2 1 globo .com
  • 17. divisão (python3) >>> 3 / 2 1.5 globo .com
  • 18. divisão (python2) from __future__ import division >>> 3 / 2 1.5 globo .com
  • 19. divisão (python2) from __future__ import division >>> 3 // 2 1 globo .com
  • 20. string.format() “{0} - {1}”.format(“andrews”, 19) “{name} - {idade}”.format(name=”andrews”, idade=19) globo .com
  • 21. comprehension {x for x in [1,2,3,3]} globo .com
  • 22. comprehension {key.upper(): value for key, value in d.items()} globo .com
  • 26. bytes e strings bytes para transferência string para representação globo .com
  • 27. bytes e strings bytes (python3) == str (python2) string (python3 == bytes (python2) globo .com
  • 28. bytes e strings (python2) u"andrews " + b"medina" u”andrews medina” globo .com
  • 29. bytes e strings (python3) >>> u"andrews " + b"medina" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Can't convert 'bytes' object to str implicitly globo .com
  • 30. strings para bytes u"andrews ".encode(“utf-8”) + b"medina" globo .com
  • 31. bytes para strings u"andrews " + b"medina".decode(“utf-8”) globo .com
  • 32. print objeto novos parâmetros (sep, end, file, flush) globo .com
  • 33. print (python2) >>> help(print) File "<stdin>", line 1 help(print) ^ SyntaxError: invalid syntax globo .com
  • 34. print (python3) >>> help(print) globo .com
  • 35. print (python2) >>> from __future__ import print_function >>> help(print) globo .com
  • 36. print (python2) >>> print(", ".join(["banana", "batata"])) banana, batata globo .com
  • 37. print (python3) >>> alimentos = ["banana", "batata"] >>> print(*alimentos, sep=", ") banana, batata globo .com
  • 38. print (python3) from StringIO import StringIO out = StringIO() >>> print("ble", file=out) >>> out.getvalue() 'blen' globo .com
  • 39. range, zip, map, filter retornam iterators globo .com
  • 40. range, zip, map, filter lista = list(range(10)) globo .com
  • 41. range, zip, map, filter for item in range(10): print item globo .com
  • 42. expections except IOError as e: globo .com
  • 43. class Class: new style por padrão globo .com
  • 44. int int = long globo .com
  • 46. annotations adiciona meta dados em uma função globo .com
  • 47. annotations def hello(name: str, age: int) -> int: print(name, age) globo .com
  • 48. annotations >>> hello.__annotations__ {'return': <class 'int'>, 'name': <class 'str'>, 'age': <class 'int'>} globo .com
  • 49. annotations >>> hello("ble", "ble") ble ble globo .com
  • 50. io io.FileIO io.StringIO io.BufferIO globo .com
  • 51. concurrent.future paralelismo globo .com
  • 52. concurrent.future interface Executor globo .com
  • 53. concurrent.future from concurrent.futures import ThreadPoolExecutor with ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(pow, 323, 1235) print(future.result()) globo .com
  • 54. concurrent.future from concurrent.futures import ProcessPoolExecutor with ProcessPoolExecutor(max_workers=4) as executor: future = executor.submit(pow, 323, 1235) print(future.result()) globo .com
  • 55. functools.lru_cache memoização nativa globo .com
  • 56. functools.lru_cache from functools import lru_cache @lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-1) + fib(n-2) globo .com
  • 60. pep 420 Implicit Namespace Packages globo .com
  • 63. branches diferentes manter dois projetos :( globo .com
  • 64. 2to3 convertor automágico globo .com
  • 65. 2to3 print “ble” -> print(ble) except Exception, e -> except Exception as e globo .com
  • 66. 2to3 2to3=true #distribute globo .com
  • 68. mesma base de código tratamento de excessões globo .com
  • 69. six :) globo .com
  • 70. leitura ‣ http://python3porting.com/ ‣ http://docs.python.org/3/ ‣ http://getpython3.com/diveintopython3/ globo .com

Editor's Notes