SlideShare ist ein Scribd-Unternehmen logo
1 von 71
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?

Weitere ähnliche Inhalte

Was ist angesagt?

Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
akaptur
 

Was ist angesagt? (20)

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

Andere mochten auch

Andere mochten auch (6)

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

Ähnlich wie Python 3

Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
Sebastian Pożoga
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 

Ähnlich wie Python 3 (20)

Python 3 - tutorial
Python 3 - tutorialPython 3 - tutorial
Python 3 - tutorial
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Python 3000
Python 3000Python 3000
Python 3000
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
EuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo DriverEuroPython 2016 : A Deep Dive into the Pymongo Driver
EuroPython 2016 : A Deep Dive into the Pymongo Driver
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 

Mehr von Andrews Medina (9)

testando interfaces web
testando interfaces webtestando interfaces web
testando interfaces web
 
desenvolvendo jogos para android
desenvolvendo jogos para androiddesenvolvendo jogos para android
desenvolvendo jogos para android
 
técnica de desenvolvimento de jogos para web
técnica de desenvolvimento de jogos para webtécnica de desenvolvimento de jogos para web
técnica de desenvolvimento de jogos para web
 
realtime - passado, presente e futuro
realtime - passado, presente e futurorealtime - passado, presente e futuro
realtime - passado, presente e futuro
 
Haskell para pythonistas
Haskell para pythonistasHaskell para pythonistas
Haskell para pythonistas
 
animações e jogos além do canvas
animações e jogos além do canvasanimações e jogos além do canvas
animações e jogos além do canvas
 
escalando aplicações django
escalando aplicações djangoescalando aplicações django
escalando aplicações django
 
Desenvolvimento de Jogos em Python
Desenvolvimento de Jogos em PythonDesenvolvimento de Jogos em Python
Desenvolvimento de Jogos em Python
 
Django Show
Django ShowDjango Show
Django Show
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n