-
2 votesanswersviews
在Python中定义unicode变量
最近,我一直在阅读有关Python源代码编码的内容,尤其是PEP 263和PEP 3120 . 我有以下代码: # coding:utf-8 s = 'abc∂´ƒ©' ƒ = 'My name is' ß = '˚ß˙ˆ†ˆ∆ ßå®åø©ˆ' print('s =', s) print('ƒ =', ƒ, 'ß =', ß) 这段代码适用于Python3,但在Python2.7中会产生 S... -
0 votesanswersviews
使用Stream线程和2个Popen进程安全地退出python3脚本
我的脚本执行以下操作: 打开一个串口并从中读取信息 将上述信息传递给另一个二进制文件,以json格式提供信息 我使用 ReaderThread 类继承 threading.Thread 接收流以提供非阻塞实现 代码细分 我创建了两个进程来执行 actisense -r /dev/ttyUSB0 | analyzer -json actisense_process = Popen(['a... -
1 votesanswersviews
与Ubuntu 16.04的Matplotlib错误
我有一个Ubuntu 16.04 LTS实例,我正在尝试运行我在Ubuntu 14.04上使用python3.5开发的旧脚本 . 我使用sudo apt-get install安装了matplotlib和底图 . 这些是我得到的错误 Traceback (most recent call last): File "contour.py", line 30, in <mod... -
0 votesanswersviews
pytesseract导入时出错
pytesseract导入中出现以下错误 . 码: from pytesseract import image_to_string from PIL import Image tessdata_dir_config='--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"' im = Image.op... -
2 votesanswersviews
Asyncio正常关闭推送服务器
考虑(其中 queue 是 asyncio.Queue ,我正在使用与标准库中的 asyncio 相同的服务器接口的asyncio websockets库): async def handler(websocket: websockets.WebSocketServerProtocol, path): while True: data = await queue.get()... -
1 votesanswersviews
为什么aiohttp导入显示以下错误?
aiohttp模块已成功安装 但不能导入如下信息 [root@ceph_admin ~]# python3 Python 3.6.5 (default, Jul 1 2018, 23:52:30) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", &qu... -
5 votesanswersviews
使用aiohttp / asyncio进行1百万请求 - 字面意思
我跟进了这个教程:https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html当我做了50 000个请求时,一切正常 . 但我需要进行1百万个API调用,然后我对此代码有问题: url = "http://some_url.com/?id={}" tasks = set... -
0 votesanswersviews
使用asyncio async和await运行python应用程序
我试图使用asyncio和关键字await / async与python 3.5我对python中的异步编程相当新 . 我对它的大部分经验都是使用NodeJS . 我似乎正在做正确的事情,除了调用我的启动函数来启动程序 . 下面是一些虚构的代码,可以解决我的困惑,因为我的代码库相当大,由几个本地模块组成 . import asyncio async def get_data(): foo... -
1 votesanswersviews
asyncio中的合作产量
我想把这个任务卸载到一个线程(现在) . 如何在这个长时间运行的任务中正确"yield"控制到eventloop,以便仍然提供Web请求(注意:我在这里使用"yield"在协同调度意义上,不是在生成器意义上,或者是python关键字 yield ) . 我的建议是做一个 await asyncio.sleep(0) ,但有保证这不仅仅是作为NOP实现的吗?我... -
37 votesanswersviews
@ asyncio.coroutine vs async def
有了我见过的 asyncio 库, @asyncio.coroutine def function(): ... 和 async def function(): ... 可互换使用 . 这两者之间有什么功能差异吗? -
1 votesanswersviews
测试从常规函数调用python协程(async def)
假设我有一些asyncio协程,它会获取一些数据并返回它 . 像这样: async def fetch_data(*args): result = await some_io() return result 基本上这个协同程序是从协程链中调用的,初始协同程序是通过创建任务来运行的 . 但是,如果出于测试目的,我只想在运行某个文件时以这种方式运行一个协程: if __name__ == '... -
4 votesanswersviews
如何在库函数中使用asyncio事件循环
我正在尝试使用asyncio, users of this function should not need to know that asyncio is involved under the hood 创建一个执行某些异步操作的函数 . 我很难理解如何使用asyncio API来完成,因为大多数函数似乎在使用get_event_loop访问的某个全局循环变量下运行,并且对此调用受此循环内的全局... -
84 votesanswersviews
Python 3.5中的协同程序和未来/任务之间的区别?
假设我们有一个虚函数: async def foo(arg): result = await some_remote_call(arg) return result.upper() 有什么区别: coros = [] for i in range(5): coros.append(foo(i)) loop = get_event_loop() loop.run_unti... -
3 votesanswersviews
假设socket.sendto是非阻塞操作是否安全?
我有一个用 socket(AF_INET, SOCK_DGRAM) 创建的套接字对象,我将在asyncio循环中使用它 . 但是我在https://docs.python.org/3/library/asyncio-eventloop.html#low-level-socket-operations找不到 sendto 函数 . 我可以安全地假设此函数是一个非阻塞系统调用,可以在asyncio循环... -
0 votesanswersviews
VTK 7.1.0 Python 3.5.2出错
在Ubuntu 16.04上使用python 3.5.2构建VTK 7.1.0时出错 . 我搜了好几次,但我没弄明白如何解决它:/ 我找到了一个关于它的对话,但他们没有找到解决方案 . 前段时间,我使用相同的python 3.5.2构建VTK并且它已经工作了,但不知何故它现在不起作用.. 这个错误的一小部分是: 在/home/joaoponte/Downloads/VTK-git/vtk/Wra... -
2 votesanswersviews
Asyncio Loop内的Asyncio循环
我刚刚开始使用Asyncio,我正在尝试使用它来解析网站 . 我正在尝试解析网站的6个部分( self.signals ),每个部分都有N个页面上有表格,所以基本上我试图异步调用哪个部分的循环,并在每个部分中异步页面 . 这就是我到目前为止所拥有的 . class FinViz(): def __init__(self): self.url = 'https://finvi... -
0 votesanswersviews
UnicodeDecodeError:'ascii' codec无法解码位置7601中的字节0xc3:序数不在范围内(128)
我目前正在运行:Python 3.5.1 :: Anaconda 4.0.0(x86_64) . 错误:UnicodeDecodeError:'ascii'编解码器无法解码位置7601中的字节0xc3:序数不在范围内(128) 运行以下代码时,我收到上述错误 . 当我保存并尝试从本地directy打开txt文件时,我遇到了同样的错误,但是,当我保存并运行一个副本时,我按照预期缩短到~25行 - 任... -
0 votesanswersviews
使用Keras .h5文件从视频流中检测对象
我正在使用keras和tensorflow来训练使用转移学习的自定义模型 . 我想知道,是否有任何教程使用keras .h5文件从实时视频流中检测自定义对象?以下是基于https://github.com/fchollet/deep-learning-with-python-notebooks/blob/master/5.3-using-a-pretrained-convnet.ipynb的培训示... -
0 votesanswersviews
sqlite3.ProgrammingError:提供的绑定数量不正确 - sqlite检测到的数字不正确
我知道关于同一主题有很多问题,但是,我没有找到解决我问题的方法 . 据我所知,这不是一个元组问题 . 我将2的元组传递给带有2个问号的查询 . Sqlite说它只需要1 . 码: def getRecipeId(categoryId, name): query = "SELECT id from tbl_recipes where name = '?' and categoryId... -
0 votesanswersviews
在python3.5或更高版本上安装python3-tk
当我尝试在ubuntu 16.04上为python3.5安装python3-tk时出现以下错误,我该怎么办? python3-tk:取决于:python3(<3.5)但是要安装3.5.1-3 -
0 votesanswersviews
pandas安装错误和python 3.5窗口中的pip更新
首先我是python的新手,并且在尝试使用 pip install pandas 安装pandas时使用3.5版本它通过使用其他命令安装一些软件包显示错误为 pip is not recognized as an internal or external command , py -3.5 -m pip install SomePackage 它显示错误 could not find a vers... -
0 votesanswersviews
kubernetes python3.5 SSLError(“坏握手:错误([('SSL routines','ssl3_get_server_certificate','certificate verify failed')],)”,)
我按照例子说明: from kubernetes import client, config config.load_kube_config() v1 = client.CoreV1Api() print("Listing pods with their IPs:") ret = v1.list_pod_for_all_namespaces(watch=False) for... -
21 votesanswersviews
解压缩一般化
>>> LOL = [[1, 2], ['three']] >>> [*LOL[0], *LOL[1]] [1, 2, 'three'] 好的!再见itertools.chain . 反正从来没有喜欢过你 . >>> [*L for L in LOL] File "<ipython-input-21-e86d2c09c33... -
0 votesanswersviews
为什么我无法导入google-cloud-speech?
我已经安装了谷歌SDK,似乎响应相当不错 . 我还下载了google-cloud-speech,用于语音转换 . 但是,当我尝试导入google.cloud时,我在IDE(Pycharm)中看不到任何关于“ Cloud ”的建议 . 我试图通过2种方式重新安装库,使用PIP和Pycharm中的另一种方式 . 他们似乎都没有工作 . 要验证我已检查已安装库的路径,并且令人惊讶地存在于那里 . 以下是... -
2 votesanswersviews
Tensorflow没有在jupyter笔记本中的GPU上运行
在Ubuntu上为GTX 1080 ti成功安装了Cuda和cudnn,在jupyter笔记本中运行一个简单的TF程序,在运行tensorflow-gpu == 1.0 vs tensorflow == 1.0的conda环境中速度不会增加 . 当我运行nvidia-smi时: +-----------------------------------------------------------... -
1 votesanswersviews
tkinter.Listbox滚动条yview
我再次遇到编写Python的一些问题,并希望寻求我的帮助 . 我继续构建我的Listbox小部件但无法设置滚动条 . 我可以将Scrollbar放在正确的位置,但是,向上和向下只是不工作并弹出一个错误,说“对象()没有参数” . 任何人都可以建议如何解决它?我附上以下代码供参考 . import tkinter from tkinter import * def test(): root... -
110 votesanswersviews
与Python 3.4相比,为什么Python 3.5中的str.translate要快得多?
我试图在Python 3.4中使用 text.translate() 从给定的字符串中删除不需要的字符 . 最小的代码是: import sys s = 'abcde12345@#@$#%$' mapper = dict.fromkeys(i for i in range(sys.maxunicode) if chr(i) in '@#$') print(s.translate(mapper))... -
0 votesanswersviews
Odoo 12字数
如何在Odoo 12中使用num2words库来显示发票报告中的总金额? 我在/base/modules/res_currency.py中找到了num2words函数 @api.multi def amount_to_text(self, amount): self.ensure_one() def _num2words(number, lang): try: ... -
0 votesanswersviews
尝试在Python 3.5中运行Sanic应用程序的未定义符号
当我尝试使用Python 3.5运行Sanic应用程序时,我收到以下错误: Traceback (most recent call last): File "api.py", line 1, in <module> from sanic import Sanic File "/home/shiro/dev/unassociated/user... -
0 votesanswersviews
我的picam到raspberry pi 3进行人脸检测,但我收到此错误
gray = cv2.cvtColor(image_frame,cv2.COLOR_BGR2GRAY)cv2.error:/home/pi/Downloads/opencv/modules/imgproc/src/color.cpp:11095:error:( - 1515)scn == 3 || scn == 4在函数cvtColor中 . 无论如何解决它而不改变picam? # Impor...