Weitere ähnliche Inhalte Ähnlich wie Python 3 (20) Mehr von Andrews Medina (9) Kürzlich hochgeladen (20) Python 32. ‣ 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
11. python3
‣ pep8
‣ zen of python
‣ generators
‣ iterators
‣ objetos
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
20. string.format()
“{0} - {1}”.format(“andrews”, 19)
“{name} - {idade}”.format(name=”andrews”, idade=19)
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
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
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
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
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
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
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
70. leitura
‣ http://python3porting.com/
‣ http://docs.python.org/3/
‣ http://getpython3.com/diveintopython3/
globo
.com
Hinweis der Redaktion \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n