我使用pyserial处理一些数据,这些数据通过1.25MBaud的串行接口传输.我使用一个非常简单的线程来收集数据:
class SerialReadThread(StoppableThread):
def __init__(self, port):
super(SerialReadThread, self).__init__()
self.serial = s.Serial(
port=port,
baudrate=1250000, # 1.25 MBaud
bytesize=s.EIGHTBITS,
parity=s.PARITY_NONE,
stopbits=s.STOPBITS_ONE,
timeout=0.5 # Do not wait longer than a half second for next message
)
self.data = []
def run(self):
# Discard old Buffer Data
self.serial.flushInput()
#self.serial.read(256)
while not self.stopped():
data = self.serial.read(64)
self.data.append(data)
log.debug(":".join("{:02x}".format(ord(c)) for c in data))
Run Code Online (Sandbox Code Playgroud)
如果我读取并处理数据,我总是在前256个字节中得到一个错误的字节.正常8字节的消息之一是9字节长,我不知道这个附加字节来自何处.如果我在启动接收器后启动发送器,则不会传输错误的字节.到目前为止唯一有效的解决方案是在线上发表评论self.serial.read(256).之后,即使我阅读了大量数据,也不会出现错误.
除了跳过第一条消息之外还有其他解决方案吗?
我正在使用Django和Haystack作为搜索引擎和后端Xapian.如何才能使所有搜索都不区分大小写?对于用户来说,如果搜索引擎忽略大小写并且只返回给定搜索查询的所有值,则会容易得多.
我的搜索索引目前看起来像这样(简化):
def ArticleIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
name = indexes.CharField(model_attr='title')
def get_model(self):
return Article
Run Code Online (Sandbox Code Playgroud)
而我使用的是SearchView与SearchForm包含在Django的草垛.
目前,对'Plat'的查询给出3个结果,这是正确的,对'plat'的查询不返回任何结果,如果搜索完成区分大小写,这也是正确的.
我想使用 cx_freeze 来冻结 python 应用程序,但我也想保留使用 pip 从源安装包的可能性。当我尝试以开发模式 ( pip install -e .)安装包时,出现如下错误。似乎 cx_freeze 使用distutils而不是setuptools在后台。是否可以强制 cx_freeze 也使用 setuptools?
D:\Python\FPF4Creator>pip install -e .
You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Obtaining file:///D:/Python/FPF4Creator
Requirement already satisfied (use --upgrade to upgrade): jinja2 in c:\winpython\python-2.7.6\lib\site-packages (from fpf4creator==0.0.2)
Requirement already satisfied (use --upgrade to upgrade): six in c:\winpython\python-2.7.6\lib\site-packages (from fpf4creator==0.0.2)
Requirement already satisfied (use …Run Code Online (Sandbox Code Playgroud) 我有一个 python 包,它具有以下目录结构
\n\npackage/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 subpackage_A/\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 moduleA.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 moduleB.py\nRun Code Online (Sandbox Code Playgroud)\n\n现在我想更改 的名称,subpackage_A同时subpackage_B保持旧名称可用,否则许多脚本会损坏。所以这应该是可能的:
package/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 subpackage_A/\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 moduleA.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 moduleB.py\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试简单地将新包导入名为 的模块中subpackage_A,但这不起作用:
from package.subpackage_B import moduleA\nfrom package.subpackage_B.moduleB import ClassB\n\n# This should, if possible, display a deprecation warning\nfrom package.subpackage_A import moduleA\nRun Code Online (Sandbox Code Playgroud)\n\n如果脚本尝试从旧位置ModuleNotFoundError导入,第一个版本会导致:moduleA
# File: package/subpackage_A.py\n# This does not work:\nfrom package.subpackage_B import * # Import everything from the new module\n\n# This is also …Run Code Online (Sandbox Code Playgroud) python ×4
cx-freeze ×1
django ×1
pyserial ×1
python-3.5 ×1
python-3.6 ×1
python-3.x ×1
setuptools ×1
xapian ×1