join()
Adam Sampson
ats1 at ukc.ac.uk
Sun Oct 8 12:25:33 EDT 2000
aahz at panix.com (Aahz Maruch) writes:
> >What other things in Python have become non-intuitive in your opinion?
>
> print >> file, "foo"
I don't see why that needs to be part of the language.
class ShiftWriter:
"""A writer class which works like C++'s ostream. For instance:
o = ShiftWriter(sys.stdout)
o << "This is a list: " << [1, 2, 3] << "\n"
"""
file = None
def __init__(self, file):
self.file = file
def __lshift__(self, arg):
self.file.write(str(arg))
return self
import sys
o = ShiftWriter(sys.stdout)
o << "This is a list: " << [1, 2, 3] << " and a number: " << 3 << "\n"
o << "I hate C++.\n"
If people want this (bleurgh), why not just add the __lshift__ method
to file objects?
--
Adam Sampson
azz at gnu.org
More information about the Python-list
mailing list