Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Will McGugan: Capturing standard output in Python (and posting it online)

$
0
0

Just landed in inthing is a new and quite interesting feature.

Version 0.1.4 adds a capture method which will record all standard output, i.e. anything you print to the terminal. It works as a context manager. Here's an example:

from inthing import Stream
stream = Stream.new()
with stream.capture() as capture:
    import this

capture.browse()

Any print statement inside the with block will be captured and posted online with the block exits.

You can also do something similar from the command line, with the inthing capture subcommand, which posts anything you pipe in to it as an event.

lets say you wanted to post the version of all you installed Python packages online. You could do something like the following:

pip freeze | inthing capture -b

For more information see the Inthing docs.

Inthing is still technically in beta, but these features are quite solid. Please give them a try, and let me know how it goes!


Viewing all articles
Browse latest Browse all 22462

Trending Articles