C++ style Stream Operators
Alex A. Nikiforov
nikifor at sky.inp.nsk.su
Tue Feb 13 04:24:25 CET 2001
Rainer Deyke <root at rainerdeyke.com> wrote:
> "Alex A. Nikiforov" <nikifor at sky.inp.nsk.su> wrote in message
> news:9661s1$1ev8j$2 at sky.inp.nsk.su...
>> Alex A. Nikiforov <nikifor at sky.inp.nsk.su> wrote:
>> > Rainer Deyke <root at rainerdeyke.com> wrote:
>> >> class ostream:
>> >> def __init__(self, buf):
>> >> self.buf = buf
>> >> def __lshift__(self, rhs):
>> >> self.buf.write(str(rhs))
>> >> cout = ostream(sys.stdout)
>> >> cout << 'Hello world!\n'
>> > what about cin ?
> Can't be done. In Python, the expression 'A >> B' cannot assign to 'B'.
>> or at least scanf ?
> Again, not possible with C-style syntax due to lack of the address-taking
> operator ('&'). There might be a function that does something similar
> (returning a tuple of values given an input string and a format string); if
> there is, I don't know about it.
There is answer on my question in Python FAQ
and there is contibuted scanf
More information about the Python-list