In Python2, print
isn't a function, it's a statement, so it can break the usual rules.
However you can write a class with the __lshift__
and __rshift__
methods
class X(object):
def __lshift__(self, n):
print "<< "*n
def __rshift__(self, n):
print ">> "*n
It's possible to make those methods do pretty much whatever you like
>>> X() << 5
<< << << << <<
>>> X() >> 10
>> >> >> >> >> >> >> >> >> >>
So you can simulate your calling idea like this
class X(object):
def __call__(self, *args, **kw):
print "called with ", args, kw
def __lshift__(self, n):
return self(n)
Not that it's a good idea, but sometimes good ideas arise from playing with things like this