Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:05:34+00:00 2026-06-15T17:05:34+00:00

Accordingly to protocol buffer python generated code documentation , I can add a object

  • 0

Accordingly to protocol buffer python generated code documentation,
I can add a object to a repeated message field this way:

foo = Foo()
bar = foo.bars.add()        # Adds a Bar then modify
bar.i = 15
foo.bars.add().i = 32       # Adds and modify at the same time

but:

  1. how can I remove bar from bars?

  2. how can I remove the n-th bar element from bars?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:05:35+00:00Added an answer on June 15, 2026 at 5:05 pm

    It took me more than a few minutes to get the proto buffer compiler installed correctly, so that may be reason enough to ignore this 🙂

    Although it isn’t in the documentation, you can actually treat a repeated field much like a normal list. Aside from its private methods, it supports add, extend, remove and sort, and remove is what you are looking for in the first case:

    foo.bars.remove(bar)
    

    Here is the output when printing foo before the above line (as defined by your code above) and after:

    Original foo:
    bars {
      i: 15
    }
    bars {
      i: 32
    }
    
    foo without bar:
    bars {
      i: 32
    }
    

    As for removing the nth element, you can use del and the index position you want to delete:

    # Delete the second element
    del foo.bars[1]
    

    And the output:

    Original foo:
    bars {
      i: 15
    }
    bars {
      i: 32
    }
    
    Removing index position 1:
    bars {
      i: 15
    }
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been here and accordingly found out that this piece of code here var
According to this Wikipedia entry: Protocol Buffers is very similar to Facebook’s Thrift protocol,
I am working on a serial commnuication protocol. In this protocol, the packt consists
I was wondering what made this protocol so useful as opposed to the other
I'm registering a custom protocol handler on my computer, which calls this application: string
I am trying to convert a PHP code to python. All values are send
NSDate conforms to NSCopying protocol. According to the documentation for NSCopying protocol: a copy
First, please tell me if I'm not allowed to ask about this protocol here...
Is there a way in Python, to have more than one constructor or more
I realise if I remove subviews accordingly from my application, the memory management seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.