Note that there are some explanatory texts on larger screens.

plurals
  1. POpython readline() returns multiple lines
    primarykey
    data
    text
    <p>I think I have created a problem for myself....</p> <p>I have two functions and a global file descriptor(file object)</p> <pre><code>def fileController(): global fd fName = ui.fileEdit.text() if ui.lineByLine.isChecked: ui.fileControl.setText('Next Line') ui.fileControl.clicked.connect(nextLine) fd = open(fName, 'r') def nextLine(): global fd lineText = fd.readline() print lineText def main(): app = QtGui.QApplication(sys.argv) global ui ui = uiClass() ui.fileControl.clicked.connect(fileController) ui.lineByLine.stateChanged.connect(lineByLineChange) sys.exit(app.exec_()) if __name__ == '__main__': main() </code></pre> <p>when nextLine() is called, it returns the first line.<br> if it is called again it returns the first line and the second line.<br> if it is called yet again it returns the first line and the second line and the third line. etc. etc.</p> <p>could the file descriptor being a global variable cause this?</p> <p>complete un-redacted code can be found <a href="https://github.com/MrRadiotron/crossTerm/blob/master/crossTerm.py" rel="nofollow">here</a></p> <p>all help is appreciated!</p> <p>EDIT: included more of the code for context<br> EDIT2: added link to github project file</p> <p>SOLVED: problem was that:</p> <pre><code>ui.fileControl.clicked.connect(nextLine) </code></pre> <p>does not disconnect the previous signal. so every time file Control() was clicked a "signal and slot" was added so that newLine() was called multiple times. And as fileController was still being called the file was being reopened. So I saw the behaviour above. Thanks for all the advice!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload