我目前 isort --profile=black --line-length=79在我的项目中用作 python 文件的 linter。
这会产生垂直悬挂缩进(isort 文档类型输出中的模式 3:
from third_party import (
lib1,
lib2,
lib3,
lib4,
)
Run Code Online (Sandbox Code Playgroud)
不过,此多行模式仅适用于行长度超过 79 个字符的情况。是否有一种模式,只要同一行上有两个或多个导入,无论行有多长,都会导致多行输出?
我尝试用 破解它 isort -m=3 --trailing-comma --line-length=1,但较短的行长度会导致多行输出,即使有一个导入,这是我不想要的:
from third_party import (
lib1,
)
Run Code Online (Sandbox Code Playgroud) 我需要使用 Python 3 解码一个按以下方式编码的字符串:
>>> s = numpy.asarray(numpy.string_("hello\nworld"))
>>> s
array(b'hello\nworld',
dtype='|S11')
Run Code Online (Sandbox Code Playgroud)
我试过:
>>> str(s)
"b'hello\\nworld'"
>>> s.decode()
AttributeError Traceback (most recent call last)
<ipython-input-31-7f8dd6e0676b> in <module>()
----> 1 s.decode()
AttributeError: 'numpy.ndarray' object has no attribute 'decode'
>>> s[0].decode()
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-34-fae1dad6938f> in <module>()
----> 1 s[0].decode()
IndexError: 0-d arrays can't be indexed
Run Code Online (Sandbox Code Playgroud) 我不知道如何设置样式表来QScrollBar修改QScrollArea.
我首先尝试过:
\n\nscrollarea = QScrollArea()\nscrollarea.verticalScrollBar().setStyleSheet("""\n QScrollBar:horizontal {\n min-width: 240px;\n height: 13px;\n }\n\n QScrollBar:vertical {\n min-height: 240px;\n width: 13px;\n }\n\n QScrollBar::groove {\n background: gray;\n border-radius: 5px;\n }\n\n QScrollBar::handle {\n background: blue;\n border-radius: 5px;\n }\n\n QScrollBar::handle:horizontal {\n width: 25px;\n }\n\n QScrollBar::handle:vertical {\n height: 25px;\n }"""\n#\xc2\xa0same for horizontalScrollBar\nRun Code Online (Sandbox Code Playgroud)\n\n然后我尝试直接在QScrollArea,但没有成功。
然后我尝试自己定义滚动条:
\n\nscrollArea = QScrollArea(self)\nverticalScrollBar = QScrollBar(qt.Qt.Vertical, scrollArea)\nverticalScrollBar.setStyleSheet(my_stylesheet)\nscrollArea.setVerticalScrollBar(verticalScrollBar)\nRun Code Online (Sandbox Code Playgroud)\n\n但完全相同的样式表适用于QSlider(通过替换QScrollBar为QSlider)。
我正在尝试使用 PIL 加载 16 位颜色 RGBA 图像。
我从以下链接下载了图像 pnggrad16rgba.png:
https://www.fnordware.com/superpng/samples.html
我检查了一下它确实有每像素 16 位的颜色通道:
但是当我尝试在 PIL 中加载数据时,我得到uint8数据:
>>> from PIL import Image
>>> import numpy
>>> im = Image.open("D:/pnggrad16rgba.png")
>>> arr = numpy.array(im)
>>> arr.dtype
dtype('uint8')
>>> arr[0, 0]
array([ 0, 0, 255, 255], dtype=uint8)
Run Code Online (Sandbox Code Playgroud)
有没有办法访问 16 位数据而不将其向下转换为uint8with PIL?
如果没有,还有什么其他库可以处理这个问题?