Last active
February 19, 2017 22:56
-
-
Save schlueter/5a4e835695f45a8ab7d04580abf17f4f to your computer and use it in GitHub Desktop.
My pythonrc
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
# pylint: disable=import-error,wildcard-import,bare-except | |
from __future__ import print_function | |
import sys | |
import traceback | |
import random | |
from pprint import pprint as pp | |
import yaml | |
from jinja2 import Template | |
try: | |
from local_init import * | |
except: | |
pass | |
assert yaml | |
assert pp | |
assert Template | |
def password(length=32): | |
print(''.join([chr(random.randint(32, 126)) for _ in range(length)])) | |
def trace(): | |
""" | |
Print the usual traceback information, followed by a listing of all the | |
local variables in each frame. | |
""" | |
sys_info = sys.exc_info()[2] | |
while 1: | |
if not sys_info.tb_next: | |
break | |
sys_info = sys_info.tb_next | |
stack = [] | |
frame = sys_info.tb_frame | |
while frame: | |
stack.append(frame) | |
frame = frame.f_back | |
stack.reverse() | |
traceback.print_exc() | |
print("Locals by frame, innermost last") | |
for frame in stack[8:]: | |
print() | |
print("Frame %s in %s at line %s" % (frame.f_code.co_name, | |
frame.f_code.co_filename, | |
frame.f_lineno)) | |
for key, value in list(frame.f_locals.items()): | |
print("\t%20s = " % key, end=' ') | |
#We have to be careful not to cause a new error in our error | |
#printer! Calling str() on an unknown object could cause an | |
#error we don't want. | |
try: | |
print(value) | |
except: | |
print("<ERROR WHILE PRINTING VALUE>") | |
# vi: set ft=python : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment