下面的代码使用SELECT DISTINCT directors.first_name, directors.last_name
FROM directors, actors
WHERE directors.first_name = actors.first_name AND directors.last_name = actors.last_name
ORDER BY directors.first_name, directors.last_name;
对象存储Python first_name last_name
Andrew Adamson
Guy Ritchie
James (I) Cameron
Jay Levey
Mel (I) Gibson
字典。
在阅读之后,字典的所有键都为data
,如下所示:
QSettings
我想知道是否可以使用常规字符串键来读取字典:
QString
代码:
{PyQt4.QtCore.QString(u'one'): 1, PyQt4.QtCore.QString(u'two'): 2}
答案 0 :(得分:1)
不可能直接,你必须将它们转换为常规字典。
d = {}
for k, v in data.items():
d[str(k)] = v
完整代码:
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
settings = QtCore.QSettings('apps', 'settings')
data = {'one': 1, 'two': 2}
settings.setValue('data', data)
data = settings.value('data').toPyObject()
d = {}
for k, v in data.items():
d[str(k)] = v
print(d)
输出:
{'two': 2, 'one': 1}
这个问题不存在,因为它返回一个常规字典,不再需要用toPyObject()转换它。
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
settings = QtCore.QSettings('apps', 'settings')
data = {'one': 1, 'two': 2}
settings.setValue('data', data)
data = settings.value('data')
print(data)
输出:
{'one': 1, 'two': 2}
答案 1 :(得分:0)
original = {PyQt4.QtCore.QString(u'one'): 1, PyQt4.QtCore.QString(u'two'): 2}
converted = {str(k): val for k, v in original.items()}