简体   繁体   English

如何取消设置协议缓冲区字段?

[英]How to unset a protocol buffer field?

How would you unset a protocol buffer variable.您将如何取消设置协议缓冲区变量。

Given this .proto :鉴于此.proto

message Product {
    optional float price = 5;
}

If one tries deleting the item:如果有人尝试删除该项目:

del product.price

this results:结果:

AttributeError: can't delete attribute

If one tries setting the variable to None :如果有人尝试将变量设置为None

product.price = None

this results:结果:

TypeError: Cannot set mypackage.Product.price_was to None: None has type <class 'NoneType'>, but expected one of: numbers.Real

You can use ClearField like您可以像这样使用ClearField

product.ClearField('price')

Full docs 完整文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM