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
# This is all that is needed to take a screenshot with PyQt5 | |
from PyQt5 import QtGui, QtWidgets | |
app = QtWidgets.QApplication([]) | |
scr = app.primaryScreen() | |
data = scr.grabWindow(0) | |
data.save("blip.png") |
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
import re, pickle, pprint, sys | |
from types import ModuleType | |
from collections.abc import Sequence, Mapping, Set | |
from contextlib import contextmanager | |
def pythonize(obj): | |
if isinstance(obj, (str, bytes)): | |
return obj |
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
class Cliente: | |
tabela = "clientes" | |
def __init__(self, id=None, nome="", telefone="", email=""): | |
self.id = id | |
self.nome = nome | |
self.telefone = telefone | |
self.email = email | |
def save(self, con, tabela=""): |
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
import random | |
import pygame | |
LARGURA, ALTURA = TAMANHO = 800, 600 | |
DROP_SIZE = 50 | |
def init(): | |
global screen, raindrop | |
screen = pygame.display.set_mode(TAMANHO) |
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
import numpy as np | |
from matplotlib import pyplot as plt | |
import math | |
# This simple example still requires X points in an ndarray, old-style: | |
x = np.arange(0, 10, .1) | |
# but for y data, we can use the class in the snippet above: | |
# replace math.sin for any function you want. | |
# Not that a scalar function is used, not one that operates on ndarrays (so, not np.sin) |
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
import pygame | |
larg, alt = 800, 600 | |
intervalo = -10, 10 | |
fator_y = 1.0 | |
tela = pygame.display.set_mode((larg, alt)) | |
f_x= lambda x:3 * x ** 2 + 2 * x + 4 |
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
import inspect | |
from functools import wraps | |
def async_init_wrapper(func): | |
def wrapper_stage1(instance): | |
async def wrapper_stage2(*args, **kw): | |
value = await func(instance, *args, **kw) | |
if value is not None: | |
raise TypeError("__async_init__() should return None") | |
return instance |
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
""" | |
Implements a for loop iterator wrapper to be used | |
in sync-loops inside async functions, so that control | |
can be yielded to the asyncio-loop after a certain | |
timeout or at each N iterations. | |
The original "in line" implementation, idea and needed were presented by | |
Nikita Melentev at the e-mail to Python-ideas list | |
stored at: |
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 contextlib import contextmanager | |
import sys | |
@contextmanager | |
def itercontext(*args): | |
contexts = [context.__enter__() for context in args] | |
try: | |
yield contexts |
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
import json, re, uuid | |
class JsonDecimalAwareEncoder(json.JSONEncoder): | |
def __init__(self, *args, **kw): | |
self.original_numbers = {} | |
super().__init__(*args, **kw) | |
def default(self, obj): | |
if isinstance(obj, decimal.Decimal): | |
key = uuid.uuid4() |