Skip to content

Instantly share code, notes, and snippets.

@ilyanep
ilyanep / clown.py
Created October 20, 2017 17:26
C++-style stream syntax in Python!
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
@ilyanep
ilyanep / PythonIsWeird
Created October 29, 2010 06:04
Python is a weird language and I'm sad
>>> 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
# 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