This file contains 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 Board(object): | |
""" | |
>>> Board().rows | |
((' ', ' ', ' '), (' ', ' ', ' '), (' ', ' ', ' ')) | |
>>> print Board() | |
| | | |
----- | |
| | | |
----- |
This file contains 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 Trie(object): | |
"""Simple Trie | |
>>> t = Trie() | |
>>> t.add('hi') | |
>>> t.add('hello') | |
>>> t.data.keys() | |
['h'] | |
>>> print t.display(), |
This file contains 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
def parse_term_state(s): | |
"""Returns TerminalState tuple given a terminal state diagram | |
>>> parse_term_state(''' | |
... label | |
... +-----+ | |
... |ABC | | |
... +-----+ | |
... |BC | | |
... |abc@ | | |
... | | |
This file contains 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
### 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 |
This file contains 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
### 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] |
This file contains 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
""" 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 |
This file contains 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 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', |
This file contains 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
from curtsies.fmtfuncs import * | |
import code | |
import traceback | |
class Interp(code.InteractiveInterpreter): | |
def showtraceback(self): | |
output_lines = [] | |
lines = ['asdf', 'asdfa.py', 'asdfasdf'] |
This file contains 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 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 |
This file contains 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
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. |