linux python2.7 protobuf_python2.7protobuf.py文件生成issu

Python类是在运行时动态生成的。在

引用您链接到的文档页面:The important line in each class is metaclass =

reflection.GeneratedProtocolMessageType. While the details of how

Python metaclasses work is beyond the scope of this tutorial, you can

think of them as like a template for creating classes. At load time,

the GeneratedProtocolMessageType metaclass uses the specified

descriptors to create all the Python methods you need to work with

each message type and adds them to the relevant classes. You can then

use the fully-populated classes in your code.

更具体地说就是:Person = _reflection.GeneratedProtocolMessageType('Person', (_message.Message,), dict(...

Person在Python类中创建。在

在Python中,类似于:

^{pr2}$

与定义常规的Person类相同。这就是在引擎盖下面用的东西。在

如果您不太熟悉元类的概念,您可能需要看看SO question或这个blog entry。在

根据上一条评论进行编辑

我不确定我是否正确地理解了你的最后一句话,但是

如果要在foo.py中使用来自addressbook_pb2.py的Person类,

将addressbook_pb2.py与foo.py相邻,并在foo.py中执行以下导入操作:from addressbook_pb2 import Person

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值