Created
June 9, 2012 21:27
-
-
Save bacher09/2902635 to your computer and use it in GitHub Desktop.
Lazy input example
This file contains hidden or 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 LazyInput(object): | |
def __init__(self, str): | |
self._str = str | |
self._as_str = None | |
def __str__(self): | |
if self._as_str is None: | |
self._as_str = raw_input(self._str) | |
return self._as_str | |
def __unicode__(self): | |
return unicode(self.__str__()) | |
def __repr__(self): | |
return self.__str__() | |
kwargs = {'test': 'val'} | |
print(kwargs.get('test', LazyInput('my test'))) | |
print(kwargs.get('print', LazyInput('my test'))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment