小编Mr.*_*. E的帖子

Sympy类Zero,One和NegativeOne,为什么它们存在?

今天我发现了这个

>>> type(1)
<class 'sympy.core.numbers.One'>
>>> type(0)
<class 'sympy.core.numbers.Zero'>
>>> type(-1)
<class 'sympy.core.numbers.NegativeOne'>
>>> type(2)
<class 'sympy.core.numbers.Integer'>
Run Code Online (Sandbox Code Playgroud)

从同意这些类型的文档中查看了文档,但它没有说明它们存在的原因.是否有理由为-1,0和1设置3个特殊单例类?

编辑:我在SymPy在线shell看到了这个

python sympy

9
推荐指数
1
解决办法
270
查看次数

Tkinter复选框/组合框下拉列表

我试图用Python创建一个后处理数据应用程序,并且正在使用Tkinter为此设计GUI。

我不知道Tkinter是否支持由复选框组成的下拉列表,然后您可以从中选择多个复选框。下图反映了我要描述的内容:

在此处输入图片说明

这可能吗?

python checkbox combobox tkinter list

5
推荐指数
1
解决办法
3173
查看次数

Futures:设置来自不同线程的结果

我有一个 http 服务器,它在线程中接收一些请求。该http服务器解析接收到的数据并将部分数据发送到不同的进程。

此进程的响应可能需要一些时间,并通过不同线程中的回调接收。

这里的问题是我需要回调函数中收到的部分响应来响应我收到的初始请求,所以我的想法是为此使用 asyncio.Task

我的代码如下:

my_futures = dict()

class HTTPHandler(http.server.BaseHTTPRequestHandle):
    do_POST(self):
        #parse data
        asyncio.create_task(self.send_response())

    async def send_response(self):
        global my_futures
        my_futures[uuid] = asyncio.get_event_loop().create_future()
        send_data_to_processB()
        await my_future
        self.send_response()

# Callback where I receive the result from process B
def on_message(message):
    global my_futures
    my_futures[message['uuid']].set_result(message['result'])

if __name__ == '__main__':
    server = http.server.HTTPServer(LISTEN_ADDR, MyHTTPHandler)
    threading.Thread(target=server.serve_forever).start()
    processB.register_callback(on_message)
Run Code Online (Sandbox Code Playgroud)

这种方法的问题是任务没有被执行并且回调根本没有收到结果。

我还尝试更改do_POST要使用的方法asyncio.run(self.send_response())而不是asyncio.create_task,使用这种方法我的回调获取结果并设置结果,但协程只是挂在await my_future

我怎样才能完成这个任务?

asynchronous coroutine python-3.x python-asyncio

3
推荐指数
1
解决办法
1370
查看次数