Some things and techniques I like python for

Table of Contents

TODO [C] [2019-07-21] hacked seaborn to display vs on pairplots python

used inspect to extract directly from local variables, lol

TODO [D] why python is good: patching seaborn bootstrap python

CREATED: [2020-01-13]

I've had nondeterministic behaviour due to random seed
was not propagated, but with a patch it's possible to achieve

# TODO careful.. need to do this ONCE
bootstrap_orig = sns.algorithms.bootstrap
def bootstrap_hacked(*args, **kwargs):
    return bootstrap_orig(*args, random_seed=0, **kwargs)
sns.algorithms.bootstrap = bootstrap_hacked

TODO [C] hacking logging.Logger to do basicConfig python

CREATED: [2019-09-17]
    format='%(asctime)s %(levelname)-8s %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S')

However if you are a well-mannered person, you don't want to mess with other loggers and you're probably providing your own logger method

This is a bit horrible

For my personal projects I'm using logzero which has got a single line setup method. However, for code I'm sharing with other people I prefer to have as little external dependencies as you can

e.g. libraries should never configure logging

[2019-09-17] could publish in r/python? python

[2019-09-17] sometimes it makes sense for your library to configure other loggers (e.g. requests) python

TODO [C] why generators are good: fbchat export example python

CREATED: [2019-12-03]

separating network retrieval and storing in database. with generators can do it simultaneously

TODO [C] another example of cool generator use in fbchat python

CREATED: [2019-12-04]
mts = int(r.timestamp)
if newest is not None and oldest is not None and newest > mts > oldest:'Fetched everything for %s',
    break # interrupt, thus interrupting fetching data
db.insert_message(thread, r)

TODO example of hacky setuplogger python

CREATED: [2019-11-04]

[C] hacky 'autonaming' python

CREATED: [2020-05-27]
import ast
import traceback
import inspect

src = ast.parse(open(__file__).read())

def find_name(lno: int):
    # TODO end_lineno is not set??
    node = None
    for x in src.body:
        if x.lineno >= lno:
        node = x
    [tg] = node.targets

class Namer:
    def auto(self) -> str:
        stack = inspect.stack()
        fr = stack[1]
        lno = fr.lineno
        return find_name(lno)

N = Namer()

aaaa = (
bbbb = (


TODO [C] why mypy is good: injector DI library pythontoblogmypy

CREATED: [2019-12-24]

TODO [D] Why python is good pythontoblog

generators, decorators and random dynamic things with examples

TODO [C] Literal types and demonstrate mypy? Perhaps timezones as example? pythontoblogmypyconfigs

CREATED: [2019-12-05]

TODO By highlighting this i will know what patterns to look for in other languages pythontoblog

CREATED: [2021-01-28]
Jump to search, settings & sitemap