Skip to content

Instantly share code, notes, and snippets.

@emberian
Created June 24, 2012 15:50
Show Gist options
  • Save emberian/2983768 to your computer and use it in GitHub Desktop.
Save emberian/2983768 to your computer and use it in GitHub Desktop.
{11:47} kb1pkl@sherman[~]$ python
Python 2.7.3 (default, Jun 15 2012, 18:14:05)
[GCC 4.7.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def write(self, msg):
... pass
...
>>> sys.stdout = Foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> import sys
>>> sys.stdout = Foo()
>>> sys.stdout.write('hello')
>>> import subprocess
>>> subprocess.call(['echo', 'hello'], stdout=subprocess.PIPE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment