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 flatten(l): | |
for el in l: | |
if isinstance(el, collections.Iterable) and not isinstance(el, basestring): | |
for sub in flatten(el): | |
yield sub | |
else: | |
yield el |
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 random | |
import unittest | |
class TestSequenceFunctions(unittest.TestCase): | |
def setUp(self): | |
self.seq = range(10) | |
def test_shuffle(self): | |
# make sure the shuffled sequence does not lose any elements |
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 test(): | |
""" | |
use -v flag to be more verbose | |
>>> test() | |
hello world | |
""" | |
print("hello world") | |
if __name__ == "__main__": | |
import doctest |
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
# http://stackoverflow.com/questions/8707457/pyqt-editable-tab-labels | |
from PyQt4 import QtGui, QtCore | |
class TabBar(QtGui.QTabBar): | |
def __init__(self, parent): | |
QtGui.QTabBar.__init__(self, parent) | |
self._editor = QtGui.QLineEdit(self) | |
self._editor.setWindowFlags(QtCore.Qt.Popup) | |
self._editor.setFocusProxy(self) | |
self._editor.editingFinished.connect(self.handleEditingFinished) |