This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| # Inspired by a friend who hadn't had her coffee yet and thought | |
| # she was writing C++ when she was in a Python file. | |
| class ostream: | |
| def __init__(self, target): | |
| self.target = target | |
| def __lshift__(self, other): | |
| self.target.write(other) | |
| return self | |
| cout = ostream(sys.stdout) | |
| endl = "\n" | |
| cout << "foo" << endl | |
| myFile = ostream(open("foo.txt", "w")) | |
| myFile << "foo" << endl |