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子文件夾。 –