This file contains hidden or 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
"""" | |
The orignal author: Alexer / #python.fi | |
""" | |
import opcode | |
import dis | |
import sys | |
import multiprocessing |
This file contains hidden or 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 ReMatch(): | |
""" | |
Small class to re.match() and to hold its result. | |
Convenient if you want to "if re.match(): ... elif re.match(): ..." | |
Usage: | |
rem = ReMatch() | |
if rem.match(...): | |
print(rem.group(1, "default value here")) | |
elif rem.match(...): | |
... |
This file contains hidden or 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 Unbuffered: | |
""" | |
Unbuffered stream emulation | |
Usage: sys.stdout = Unbuffered(sys.stdout) | |
""" | |
def __init__(self, stream): | |
self.stream = stream | |
def write(self, data): | |
self.stream.write(data) | |
self.stream.flush() |
This file contains hidden or 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
#!/usr/bin/env python3 | |
# | |
# pydump | |
# A Python3 pretty-printer that also does introspection to detect the original | |
# name of the passed variables | |
# | |
# Jean-Charles Lefebvre <[email protected]> | |
# Latest version at: http://gist.github.com/polyvertex (pydump) | |
import sys |
This file contains hidden or 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 ast | |
def dbg_astdump(node, annotate_fields=True, include_attributes=False, indent=' '): | |
""" | |
AST Pretty Printer | |
Code copied and slightly modified from: | |
http://alexleone.blogspot.com/2010/01/python-ast-pretty-printer.html | |
""" | |
def _format(node, level=0): | |
if isinstance(node, ast.AST): |
NewerOlder