在下面的例子中,我希望所有元素都是元组,为什么元组只包含一个字符串时转换为字符串?
>>> a = [('a'), ('b'), ('c', 'd')]
>>> a
['a', 'b', ('c', 'd')]
>>>
>>> for elem in a:
... print type(elem)
...
<type 'str'>
<type 'str'>
<type 'tuple'>
Run Code Online (Sandbox Code Playgroud) 我正在使用PyQt并遇到了这个问题.如果我的import语句是:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
Run Code Online (Sandbox Code Playgroud)
然后pylint给出了数百个"未使用的导入"警告.我很犹豫要把它们关闭,因为可能有其他未使用的导入实际上很有用.另一种选择是这样做:
from PyQt4.QtCore import Qt, QPointF, QRectF
from PyQt4.QtGui import QGraphicsItem, QGraphicsScene, ...
Run Code Online (Sandbox Code Playgroud)
and I end up having 9 classes on the QtGui line. There's a third option, which is:
from PyQt4 import QtCore, QtGui
Run Code Online (Sandbox Code Playgroud)
and then prefix all the classes with QtCore or QtGui whenever I use them.
At this point I'm agnostic as to which one I end up doing in my project, although the last one seems the …