相关疑难解决方法(0)

如何创建只有一个元素的元组

在下面的例子中,我希望所有元素都是元组,为什么元组只包含一个字符串时转换为字符串?

>>> 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)

python

88
推荐指数
3
解决办法
4万
查看次数

是否应该避免使用通配符?

我正在使用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 …

python pyqt pylint pyqt4 python-import

48
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×2

pylint ×1

pyqt ×1

pyqt4 ×1

python-import ×1