PyQt5的文件系统

Class: QIODevice, QFileDevice, QFile, QTemporaryFile,……

QFile的用法:

QFile myFile = QFile("filename")
myFile.open(OpenMode mode)

这里OpenMode是一个枚举类型,只能是一下几种类型:


image.png

Certain flags, such as Unbuffered and Truncate, are meaningless when used with some subclasses. Some of these restrictions are implied by the type of device that is represented by a subclass. In other cases, the restriction may be due to the implementation, or may be imposed by the underlying platform; for example, QTcpSocket does not support Unbuffered mode, and limitations in the native API prevent QFile from supporting Unbuffered on Windows.

The OpenMode type is a typedef for QFlags . It stores an OR combination of OpenModeFlag values.


可以通过用|来连接两个不同的值如:

myFile.open( QIODevice.ReadOnly | QIODevice.Text )

类似于不同位上的开关同时打开

OpenMode类型是抽象模板QFlags的一种定义

open函数若打开文件成功会返回True否则返回False
但如果打开开关Write, 那么当文件不存在是会新建一个空白文件

QFile的其他用法

你可能感兴趣的:(PyQt5的文件系统)