问题描述
也许我确实错过了文档中的一些要点,但是我正在努力寻找一些简单, pythonic 方式来阅读重复 gRPC字段。
假设我们有一些protodef:
message Bar
{
repeated float vals = 1;
}
message Foo
{
repeated Bar bars = 1;
}
service FooService
{
rpc GetFoo(Foo) returns (Foo) {}
}
在Foo
(服务方)中读取Foo
和Bar
的{{1}}的{{1}}值的简单,Python方式是什么?
目标是将封装的重复浮点数读取到单独的列表或NumPy数组中。
我尝试按索引访问或通过迭代器样式进行循环,例如:
GetFoo
不幸的是,这引发了异常,即消息对象...
def GetFoo(self,request,context):
bar1 = request.bars[0]
...
并简单地迭代了这些点:
...has no len()
...引发了一个异常...
def GetFoo(self,context):
point_lists = list()
for bar in request.bars:
points = [v for v in bar]
point_lists.append(points)
...
,因此我无法遍历单点(尽管我没有得到atm的原因,为什么当Bar object is not iterable
也是Bar
时,Foo
不可迭代重复类型,并且 可以迭代)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)