Created
February 24, 2017 23:12
-
-
Save joelburton/9c5656ca2057801eea6414719bde4db1 to your computer and use it in GitHub Desktop.
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 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