小编Int*_*per的帖子

列表子类的 Python 类型

我希望能够定义列表子类的内容。该类将如下所示。

class A(list):
   def __init__(self):
      list.__init__(self)
Run Code Online (Sandbox Code Playgroud)

我想包括打字,以便发生以下情况。

import typing

class A(list: typing.List[str]):  # Maybe something like this
   def __init__(self):
      list.__init__(self)

>> a = A()
>> a.append("a")  # No typing error
>> a.append(1)  # Typing error
Run Code Online (Sandbox Code Playgroud)

python list subclass python-3.x python-typing

10
推荐指数
1
解决办法
2554
查看次数

用 Python 打印队列的内容

如果我使用 python 模块 queue.Queue,我希望能够使用不弹出原始队列或创建新队列对象的方法打印出内容。

我曾尝试考虑进行获取,然后将内容放回原处,但这成本太高了。

# Ideally it would look like the following
from queue import Queue
q = Queue()
q.print()
q.put(1)
q.print()

>> [] # Or something like this
>> [1] # Or something like this
Run Code Online (Sandbox Code Playgroud)

python queue logging

6
推荐指数
1
解决办法
2万
查看次数

如何让Google Protobuf在Matlab中工作?

因此,如果想要在Matlab中使用Google协议缓冲区并使用Windows计算机,那么最好的方法是什么,因为Matlab不在支持的语言列表中?

matlab protocol-buffers

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