Skip to content

Instantly share code, notes, and snippets.

@bacher09
Created June 9, 2012 21:27
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 bacher09/2902635 to your computer and use it in GitHub Desktop.
Save bacher09/2902635 to your computer and use it in GitHub Desktop.
Lazy input example
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