Skip to content

Instantly share code, notes, and snippets.

@joelburton
Created February 24, 2017 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelburton/9c5656ca2057801eea6414719bde4db1 to your computer and use it in GitHub Desktop.
Save joelburton/9c5656ca2057801eea6414719bde4db1 to your computer and use it in GitHub Desktop.
import sys
from cStringIO import StringIO
class fake_input(object):
def __init__(self, *args):
text = "\n".join(args) + "\n"
self.stdin = sys.stdin
self.input = StringIO(text)
def __enter__(self):
sys.stdin = self.input
def __exit__(self, type, value, tb):
sys.stdin = self.stdin
def funky():
"""Test
>>> with fake_input("hello", "joel"):
... funky()
hello
joel
"""
while True:
x = raw_input()
print x
if x == "joel":
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment