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 |
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
>>> len = 3 | |
>>> len([3]) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: 'int' object is not callable | |
>>> del(len) | |
>>> len([3]) | |
1 | |
>>> False = 3 |
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
# Suppose I want to the user to enter names one at a time, until the user enters a blank line, | |
# then tell each name that they're awesome. In a typical programming language, my first instinct | |
# would be to do: | |
while (name = gets.chomp) != "" | |
puts name + ", you are so awesome" | |
# or perhaps alternatively, to get the names to print afterwards | |
names = Array.new |