michaelrbock
michaelrbock

Reputation: 1270

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

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?

Upvotes: 7

Views: 8352

Answers (2)

cs95
cs95

Reputation: 402593

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

Upvotes: 4

michaelrbock
michaelrbock

Reputation: 1270

Use a combination of del and [:]:

del foo.bars[:]

Upvotes: 7

Related Questions