在__main__.py
文件中,
QtCore.qDebug(QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation))
输出
/home/admin/.local/share/__main__.py
而不仅仅是
/home/admin/.local/share
为什么最后附加__main__.py
?这是一个错误吗?
答案 0 :(得分:0)
这不是错误,这是正确的。
如果审核了docs:
<强> MACOS 强>:
"~/Library/Application Support/<APPNAME>"
,"/Library/Application Support/<APPNAME>"
。"<APPDIR>/../Resources"
<强>窗强>
"C:/Users/<USER>/AppData/Local/<APPNAME>"
,"C:/ProgramData/<APPNAME>"
,"<APPDIR>"
,"<APPDIR>/data"
,"<APPDIR>/data/<APPNAME>"
<强>的Linux 强>
AppLocalDataLocation
"~/.local/share/<APPNAME>"
,"/usr/local/share/<APPNAME>"
,"/usr/share/<APPNAME>"
注意,所有以<APPNAME>
结束,如果未建立名称,则将采用主文件的名称:
from PyQt5.QtCore import *
if __name__ == '__main__':
import sys
app = QCoreApplication(sys.argv)
qDebug("applicationName: "+ app.applicationName())
qDebug(QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation))
app.setApplicationName("MyApp")
qDebug("applicationName: " + app.applicationName())
qDebug(QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation))
输出:
applicationName: main.py
/home/eyllanesc/.local/share/main.py
applicationName: MyApp
/home/eyllanesc/.local/share/MyApp