Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created July 17, 2010 14:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tswicegood/479549 to your computer and use it in GitHub Desktop.
Save tswicegood/479549 to your computer and use it in GitHub Desktop.
class QuickOutputter(object):
def __lt__(self, msg):
print msg
return self
o = QuickOutputter()
o < "Some random message"
o < "Some other message"
@tswicegood
Copy link
Author

Playing around with an idea for making generating output quicker/more concise in Python. Thoughts?

@HugoArts
Copy link

if this is in any way better than the regular print statement, your example does not make it obvious. It's more like you're forcing C++ cin/cout onto python, for no good reason. But if that's what you want, why not use __lshift__?

@medecau
Copy link

medecau commented Jul 17, 2010

o < "neat"

@superbobry
Copy link

your way of printing doesn't support redirection the print statement has
print >>sys.stderr, "Some random message"

generally, i think this only makes the code harder to read, rather then making it "more concise"

@tswicegood
Copy link
Author

@superbobry: yup - not trying to mimic the print >>sys.std* syntax. The idea would be that you call log.set_default_output for a printer, then do o.stderr < "something" or log.warn < "omg!".

Agreed - concise doesn't always make more readable - just trying to see what the thoughts where out there on this style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment