[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QTextstream >>
From:       Chris Pezley <chris.pezley () quantumwise ! com>
Date:       2017-06-20 9:03:14
Message-ID: 0851123e-6051-1f85-b4c6-395ae52af8d1 () quantumwise ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 06/19/2017 05:36 PM, Christopher Probst wrote:
> Hi,
>
> I am loving the PyQt. I want to confirm that the operator ">>" 
> QTextStream operator does not work in PyQt5. This will not work:
> file = QFile("myfile.txt")
>
> if file.open(QIODevice.ReadOnly):
>      stream = QTextStream(file)
>      stream >>value
>      stream >> text >>value
> What are the preferred ways to deserialize an QIODevice in PyQt?
>
> Thanks,
> Christopher
The rrshift and rlshift operators won't work like that with QTextStream, no.

I would go with using python's build in functionality for files instead:

with open("myfile.txt", "r") as my_file:
     value = my_file.read()

See the python documentation for more: 
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files



[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 06/19/2017 05:36 PM, Christopher Probst wrote:<br>
    <blockquote type="cite"
cite="mid:CABhWjnrRF-sMpP-94r8yuOkG7A=LyfHaHhVEjvJG3JCMXkJqMg@mail.gmail.com">
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>I am loving the PyQt. I want to confirm that the operator
          "&gt;&gt;" QTextStream operator does not work in PyQt5. This
          will not work:
          <pre style="color:rgb(0,0,0);font-family:&quot;DejaVu Sans \
Mono&quot;;font-size:11.4pt">file = QFile(<span \
style="color:rgb(0,128,128);font-weight:bold">"myfile.txt"</span>)

<span style="color:rgb(0,0,128);font-weight:bold">if \
</span>file.open(QIODevice.ReadOnly):  stream = QTextStream(file)
    stream &gt;&gt; <span style="background-color:rgb(228,228,255)">value</span>
    stream &gt;&gt; text &gt;&gt; <span \
                style="background-color:rgb(228,228,255)">value</span></pre>
          <pre style="color:rgb(0,0,0);font-family:&quot;DejaVu Sans \
Mono&quot;;font-size:11.4pt"><span style="background-color:rgb(228,228,255)"> \
</span></pre>  What are the preferred ways to deserialize an QIODevice in
          PyQt?</div>
        <div><br>
        </div>
        <div>Thanks,<br>
          Christopher<br>
        </div>
      </div>
    </blockquote>
    The rrshift and rlshift operators won't work like that with
    QTextStream, no.<br>
    <br>
    I would go with using python's build in functionality for files
    instead:<br>
    <br>
    with open("myfile.txt", "r") as my_file:<br>
        value = my_file.read()<br>
    <br>
    See the python documentation for more:
<a class="moz-txt-link-freetext" \
href="https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files">h \
ttps://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files</a><br>  \
<br>  <br>
  </body>
</html>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://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