import PyQt5.QtCore as QtCore file = QtCore.QFile("text_file.txt") if not file.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text): print("Failed to open file.") else: # Read file line-by-line and print contents while not file.atEnd(): line = file.readLine() print(str(line, encoding="utf-8").strip()) file.close()
import PyQt5.QtCore as QtCore input_file = QtCore.QFile("binary_file.dat") output_file = QtCore.QFile("output.dat") if not input_file.open(QtCore.QIODevice.ReadOnly) or not output_file.open(QtCore.QIODevice.WriteOnly): print("Failed to open files.") else: # Read file line-by-line and write contents to output file while not input_file.atEnd(): line = input_file.readLine() output_file.write(line) input_file.close() output_file.close()Package Library: The package library used in these examples is PyQt5.QtCore, which is part of the PyQt5 package for Python. This package provides a set of Python bindings for the Qt application framework, including modules for GUI development, multimedia, networking, and more.