This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Respondendo a questões feitas no grupo da live de Python. | |
""" | |
class Teste: | |
bananas_cls = 5 # Variável de classe | |
def __init__(self): | |
"""Método que inicia a instância.""" | |
self.bananas_self = 10 # Variável de instância |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Exemplo de como compartilhas uma queue com processos e threads.""" | |
from collections import namedtuple | |
from multiprocessing import Process, Queue | |
from threading import Thread | |
from os import getppid, getpid | |
q = Queue() | |
pstate = namedtuple('pstate', 'name ppid pid') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Exemplo de classe e objeto. | |
Criado para rapidinha #7: https://youtu.be/SQXmC6PbZWk | |
""" | |
class Personagem: | |
"""Molde para o rato.""" | |
def __init__(self, nome, cor): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multipledispatch import dispatch # pip | |
class Pedra: | |
def __repr__(self): | |
return 'Pedra' | |
class Papel: | |
def __repr__(self): | |
return 'Papel' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncio import get_event_loop | |
from collections.abc import AsyncIterator | |
from typing import Iterator, Collection, Dict | |
from types import coroutine | |
from functools import singledispatch | |
@singledispatch | |
def aiter(iterator): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
class Dispatcher: | |
def __init__(self, func): | |
self.func = func | |
self.slots = [] | |
def __call__(self, arg): | |
for func, arg_type in self.slots: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Alternativa ao multiplo aninhamento de código. | |
Problema proposto pelo @rg3915 | |
Código antigo: | |
for k, v in variant_list.items(): | |
if v: | |
try: | |
v = float(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ast import literal_eval | |
def convert_to_type(input_data): | |
try: | |
return literal_eval(input_data) | |
except (ValueError, SyntaxError): | |
return input_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from module_login import POLogin | |
def before_tag(context, tag): | |
if tag == 'login': | |
POLogin.do_login(user, passw) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker stop $(docker ps -q -a) | |
docker rm -f $(docker ps -q -a) | |
docker volume prune -f | |
docker rmi -f $(docker images -q -a) |