1
我刚刚通过pip安装了retext。我必须为它下载图标,但我意识到它不起作用(菜单上没有图标),除非我在retext文件夹中运行“retext”。这是什么“加入”在做什么?
我试图解决它,但我的蟒蛇技能不是很强。
目前,我强制icon_path有我想要的路径。
#icon_path = 'icons/'
icon_path = '/usr/local/lib/python3.5/site-packages/retext/icons/'
有人能告诉我这条线是如何工作的吗?
datadirs = [join(d, 'retext') for d in datadirs]
谢谢。
import sys
import markups
import markups.common
from os.path import dirname, exists, join
from PyQt5.QtCore import QByteArray, QLocale, QSettings, QStandardPaths
from PyQt5.QtGui import QFont
app_version = "6.0.1"
settings = QSettings('ReText project', 'ReText')
if not str(settings.fileName()).endswith('.conf'):
# We are on Windows probably
settings = QSettings(QSettings.IniFormat, QSettings.UserScope,
'ReText project', 'ReText')
datadirs = QStandardPaths.standardLocations(QStandardPaths.GenericDataLocation)
datadirs = [join(d, 'retext') for d in datadirs]
if sys.platform == "win32":
# Windows compatibility: Add "PythonXXX\share\" path
datadirs.append(join(dirname(sys.executable), 'share', 'retext'))
if '__file__' in locals():
datadirs = [dirname(dirname(__file__))] + datadirs
#icon_path = 'icons/'
icon_path = '/usr/local/lib/python3.5/site-packages/retext/icons/'
for dir in datadirs:
if exists(join(dir, 'icons')):
icon_path = join(dir, 'icons/')
break
'join'来自您的最终导入语句:'from os.path import dirname,exists,join'。它用于组合路径段。有关更多信息,请参阅os.path上的官方python文档。 'datadirs = [join(d,'retext')for d in datadirs]'是一个[list comprehension](https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions) 'datadirs'中的目录路径与路径段''retext''。你基本上是得到'datadirs'中每个目录路径的retext子文件夹。 –