I use PyQt, and I noticed strange behavior when testing my application on Windows (everything works as expected on Linux).
I have a file that I can read and write, and I want to check it in the application:
>>> from PyQt4.QtCore import QFile, QFileInfo
>>> f1 = QFileInfo("C:\Users\Maxime\Desktop\script.py")
>>> f2 = QFile("C:\Users\Maxime\Desktop\script.py")
>>> f1.isWritable()
True
>>> f2.isWritable()
False
So it seems to be QFilewrong in this case. But in another read-only file:
>>> f1 = QFileInfo("C:\Program Files (x86)\MySoftware\stuff\script.py")
>>> f2 = QFile("C:\Program Files (x86)\MySoftware\stuff\script.py")
>>> f1.isWritable()
True
>>> f2.isWritable()
False
Now this QFileInfois what is wrong!
So, I decided that instead I should use os.access:
>>> import os
>>> os.access("C:\Users\Maxime\Desktop\script.py")
True
>>> os.access("C:\Program Files (x86)\MySoftware\stuff\script.py")
True
So, it is os.accessalso erroneous in one case and returns the same results as QFileInfo.
I have a few questions:
- I am not familiar with Windows, is there something that I am missing?
- Qt,
QFileInfo QFile, , . ? - Qt ( Python?), , Linux Mac OS.
Edit:
, QFile:: isWritable() False, .
>>> f = QFile("C:\Users\Maxime\Desktop\script.py")
>>> f.open(QFile.WriteOnly)
True
>>> f.isWritable()
True
>>> f = QFile("C:\Program Files (x86)\MySoftware\stuff\script.py")
>>> f.open(QFile.WriteOnly)
False
>>> f.isWritable()
False