News for hackers. Stuff that matters.
Re: (Python) Generator Tricks For Systems Programmer (pdf) by pyre on Tuesday December 13, 2011 @08:48PM (#3350230)
I've got an implementation of tee in Python. Python itself comes with a reverse tee (reading from multiple files/file-like objects), but there was nothing out there for writing once to multiple file (or file-like objects).

It wasn't as easy as one would think, because trying to use it in conjunction with something like subprocess.Popen() presents a problem since it requires a file object that has an actual file handle (i.e. file.fileno()) rather than just some mock-object that implements the right instance methods.

I need to get it up on github and/or pypi.

Re: (Python) Generator Tricks For Systems Programmer (pdf) by bockris on Wednesday December 14, 2011 @08:42AM (#3351749)
Re: (Python) Generator Tricks For Systems Programmer (pdf) by pyre on Wednesday December 14, 2011 @12:49PM (#3352771)
That's not the tee that I'm talking about.

This takes one iterator and returns n multiple iterators:

http://docs.python.org/library/itertools.html#itertools.tee

This is what I'm talking about when I'm talking about tee:

http://linux.die.net/man/1/tee

Python has a reverse tee:

http://docs.python.org/library/fileinput.html

This iterates over input from multiple sources, but my implementation takes input from a single source and writes it to multiple destinations.