diff --git a/python23six.html b/python23six.html index 112ab01..624e1fc 100644 --- a/python23six.html +++ b/python23six.html @@ -58,25 +58,132 @@
-

Por que Python 3?

- - - - -

+
+

Por que Python 3?

+ + +
+ +
+ + + +
+
+
+

Caminho para o Python 3

- + +
+ +
+

O que 2to3 arruma

+ + + +

(% para formatar strings + retornou, 2to3 não muda para format())

+
+
+ +
+
+

"Mais minha infra usa Centos 4 e não tem Python 3 pra Centos!"

+ +
+ +
+

Six ao resgate!

+ +

e seu fiel companheiro __future__!

+
+
+

Exemplo (estúpido)

+
import collections
+
+class Model(object):
+    def __init__(self, word):
+        self._count = None
+        self.word = word
+        return
+
+    @property
+    def word(self):
+        return self._word
+
+    @word.setter
+    def word(self, word):
+        self._word = word
+        self._count = collections.Counter(word)
+
+ +
+

+    @property
+    def letters(self):
+        return self._count
+
+    def __getitem__(self, pos):
+        return self._count[pos]
+						
+
+ +
+

+if __name__ == "__main__":
+    word = Model('This is an ex-parrot')
+    for letter, count in word.letters.iteritems():
+        print letter, count
+						
+
+ +
+

E Python 3?

+ +

class Model(object):

+ +

Todas as classes são new style, mas Python 3 não + reclama disso.

+
+ +
+

E Python 3?

+ +

for letter, count in word.letters.iteritems():

+

iteritems() não existe mais no Python 3.

+

Python 3 tem apenas items(), + que funciona de forma diferente no Python 2.

+

items() no Python 2 gera uma + lista inteira nova ao invés de ser um iterador.

+
+ +
+

E Python 3?

+ +

print letter, count

+ +

print agora é uma função.

+ +

Algumas funcionalidades mudaram (por exemplo, não há + mais espaço entre itens).

+
+
+ @@ -85,25 +192,25 @@