from code import InteractiveConsole console = InteractiveConsole() contents = ''' try: import cPickle as pickle # python 2.7 except ImportError: import _pickle as pickle # python 3.2 class Example: def __init__(self): self.name = "Hello" def __repr__(self): return "an Example object named " + self.name obj = Example() obj f = open("testpickle.pkl", 'wb') pickle.dump(obj, f) ''' for line in contents.splitlines(): console.push(line)