I am trying to write a Python class that will allow me to use it in code like this:
mc = MyClass()
mc.foo()
.bar()
I have written the class like this:
class MyClass(object):
def __init__(self):
pass
def foo(self):
print "foo called"
return self
def bar(self):
print "bar called"
return self
However, the only way I can get close to the "beautiful" style I want, is to introduce backslashes like so (run in both IPython and IDLE):
>>> mc = MyClass()
>>> mc.foo()\
.bar()
Is there any way I can do without the backslashes?