Skip to content

Instantly share code, notes, and snippets.

class Board(object):
"""
>>> Board().rows
((' ', ' ', ' '), (' ', ' ', ' '), (' ', ' ', ' '))
>>> print Board()
| |
-----
| |
-----
class Trie(object):
"""Simple Trie
>>> t = Trie()
>>> t.add('hi')
>>> t.add('hello')
>>> t.data.keys()
['h']
>>> print t.display(),
def parse_term_state(s):
"""Returns TerminalState tuple given a terminal state diagram
>>> parse_term_state('''
... label
... +-----+
... |ABC |
... +-----+
... |BC |
... |abc@ |
... | |
### current bpython session - file will be reevaluated, ### lines will not be run
class Mapping(object):
def __init__(self):
self.data = []
def add_key_value_pair(self, key, value):
self.data.append([key, value])
def get_value(self, key):
for k, value in self.data:
if k == key:
return value
### current bpython session - file will be reevaluated, ### lines will not be run
class Mapping(object):
def __init__(self):
self.dict = {}
def add_key_value_pair(self, key, value):
self.dict[key] = value
def get_value(self, key):
return self.dict[key]
def remove_key(self, key):
del self.dict[key]
""" Evidence the += method is bad:
In [4]: def plusequals():
...: s = ''
...: for x in 'asdf'*1000:
...: s += x
In [5]: plusequals()
In [6]: def joinmethod():
...: l = 'asdf'*1000
import sys
from pygments.style import Style
from pygments.token import *
from pygments.formatter import Formatter
from curtsies.bpythonparse import parse
default_colors = {
'keyword': 'y',
'name': 'c',
'comment': 'b',
from curtsies.fmtfuncs import *
import code
import traceback
class Interp(code.InteractiveInterpreter):
def showtraceback(self):
output_lines = []
lines = ['asdf', 'asdfa.py', 'asdfasdf']
import code
import re
import select
import signal
import socket
import sys
from curtsies import input
from curtsies.fmtfuncs import green, blue
from subprocess import Popen, PIPE
tom-mba:~ tomb$ ipython
Python 2.7.5 (default, Nov 26 2013, 10:28:53)
Type "copyright", "credits" or "license" for more information.
IPython 2.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.