On Jul 15, 11:55 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] writes:
> > I just came across this unusual situation where I'd like to modify a
> > string passed to a function
>
> Again: Why? The normal way to do this is to create a new string and
> return that.
>
<snip>

Yes, usually, but that won't work in this case (look at my previous
post around the 'cin >> line' line). This is what I came up with:

class StreamLineBuffer:
    def __init__(self):
            self.buf = ""

    def __rrshift__(self, stream):
            self.buf = stream.readline()

    def __str__(self):
            return self.buf

cin = sys.stdin
buf = StreamLineBuffer()

cin >> buf
line = str(buf)

Works like a charm :)

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to