[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Where is the "<<" insertion overload done?
From: Dmitry Shachnev <mitya57 () ubuntu ! com>
Date: 2014-11-25 6:48:30
Message-ID: CAKimPHU_mYspNboJE2Pbc2ps6BPyM6mtye+398zr5fXeH=3x4A () mail ! gmail ! com
[Download RAW message or body]
Hi,
On Tue, Nov 25, 2014 at 8:17 AM, David Cortesi <davecortesi@gmail.com> wrote:
> I've been happily using the "<<" insertion operator to write to QTextStreams
> for some time now, and only recently realized that "<<" is binary shift left
> in standard Python. Well, not so much realized, as had it rubbed in my face
> by PyLint, which warns that "stream << string" is an expression whose value
> is not being assigned.
>
> Somehow a QTextStream (derived) object arranges an overloaded meaning of
> ".write()" onto this operator. But where/how is the overload done?
Just like any other operator overload. Search for 'lshift_slot' in sip code.
Simple example code (in Python) if you want to do this yourself is attached.
--
Dmitry Shachnev
["test.py" (text/x-python)]
#!/usr/bin/env python3
class Printer:
def __lshift__(self, value):
print(value, end='')
return self
def __del__(self):
print()
if __name__ == '__main__':
Printer() << 'mitya' << 57
[Attachment #4 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic