How do you remove all elements from a repeated Proto field in Python?

6.2k Views Asked by At

Suppose I have the .proto file:

message Bar { }

message Foo {
  repeated Bar bars = 1;
}

How can you delete all of the elements in the field bar?

2

There are 2 best solutions below

0
On

Use a combination of del and [:]:

del foo.bars[:]
0
On

You can use foo.ClearField('bars') or del foo.bars[:].