在PyDev中使用协议缓冲区时,导入时未定义变量 [英] Undefined variable from import when using protocol buffers in PyDev

查看:54
本文介绍了在PyDev中使用协议缓冲区时,导入时未定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用协议缓冲区的PyDev项目.协议缓冲区文件位于由协议编译器生成的zip文件中.当我运行程序时,一切正常,但是PyDev为每个枚举常量报告导入时未定义的变量".例如:

I've got a PyDev project that uses protocol buffers. The protocol buffer files are located in a zip file generated by the protoc compiler. Everything works when I run the program, however PyDev reports "Undefined variable from import" for every enumeration constant. So for example:

import model_pb2

value = model_pb2.Expression(type = model_pb2.Expression.PARAMETER)

它将枚举常量"PARAMETER"报告为未定义变量.我的程序中有几十个类似的错误,我想适当地"修复它们(即,不只是抑制警告.)

It reports the enum constant "PARAMETER" as being an undefined variable. There are several dozen similar errors in my program, and I'd like to fix them "properly" (i.e. not simply suppressing the warning.)

推荐答案

我在protobuf 2.6.1和PyDev 4.5.5上遇到了此问题.我尝试了以上建议,但对我而言,这些建议均无济于事.使用protobuf枚举时,最终摆脱了未定义变量"错误的原因很简单:

I encountered this issue with protobuf 2.6.1 and PyDev 4.5.5. I tried the suggestions above both none of them helped in my case. What ended up getting rid of the 'undefined variable' errors when using protobuf enums was simple:

访问已实例化的protobuf对象而不是protobuf模块上的枚举.

我不确定是否可以将其应用于OP的用例,但是在我看来,这很简单:

I'm not sure if this could be applied to the OP's use case, but in mine it was as easy as:

from myprotobuf_module import SomeProtobufMessage

some_protobuf_object = SomeProtobufMessage()
some_enum = some_protobuf_object.SOME_ENUM

这篇关于在PyDev中使用协议缓冲区时,导入时未定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆