A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
from abc import abstractmethod, ABC | |
from enum import auto, Enum | |
class Stateful(ABC): | |
@abstractmethod | |
def _stateful_get(self): | |
pass | |
@abstractmethod |
from random import randint | |
from time import perf_counter | |
from typing import Callable, MutableSequence, Union | |
ItemsType = MutableSequence[Union[int, float]] | |
def bubble_sort(items: ItemsType): | |
"""Simple iterative forward marching pairwise sort algorithm.""" | |
requires_new_pass = True |
class QNode(QGraphicsWidget): | |
def __init__(self): | |
super().__init__() | |
self._headerWidget = QGraphicsWidget(self) | |
self._centerWidget = QGraphicsWidget(self) | |
self._centerLayout = QGraphicsLinearLayout(Qt.Horizontal, self._centerWidget) |
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "hivemap", | |
"type": "object", | |
"properties": { | |
"nodes": { | |
"type": "array", | |
"items": { | |
"$ref": "#/definitions/node" | |
} |
{ | |
"nodes": [ | |
{ | |
"name": "my_hive", | |
"position": { | |
"x": 1.0, | |
"y": 2.0 | |
}, | |
"folded_pins": [ | |
"score_out" |
class Deferred: | |
def __init__(self, call, *args, **kwargs): | |
self.call = getattr(call, 'func', call) | |
self.args = args | |
self.kwargs = kwargs | |
def result(self): | |
return self.call(*self.args, **self.kwargs) | |
# Inspiration from http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/ | |
def y_comb(f): | |
def outer(x): | |
def inner(y): | |
return (x(x))(y) | |
return f(inner) | |
return outer(outer) |
jack_data = {"name": "jack", | |
"age": 8, | |
"parent": None} | |
jill_data = {"name": "jill", | |
"age": 4, | |
"parent": None} | |
data = { | |
'name': "bob", | |
"jack_data": jack_data, |
class DLListItem: | |
def __init__(self, value): | |
self.next = None | |
self.previous = None | |
self.value = value | |
def append(self, other) -> 'DLListItem': | |
self.next = other | |
other.previous = self | |
return other |