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 7695797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:37:41+00:00 2026-05-31T21:37:41+00:00

In Flask-PyMongo, they use self._Collection__database to represent the database object that this Collection object

  • 0

In Flask-PyMongo, they use self._Collection__database to represent the database object that this Collection object belongs to:

class Collection(collection.Collection):
    """Custom sub-class of :class:`pymongo.collection.Collection` which
    adds Flask-specific helper methods.
    """

    def __getattr__(self, name):
    attr = super(Collection, self).__getattr__(name)
    if isinstance(attr, collection.Collection):
        db = self._Collection__database
        return Collection(db, attr.name)
    return attr

Why is self._Collection__database not self.__database?

test <a>and <i>
  • 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-05-31T21:37:43+00:00Added an answer on May 31, 2026 at 9:37 pm

    Flask-PyMongo is not arbitrarily choosing that name.
    The name is the result of name mangling:

    Since there is a valid use-case for class-private members (namely to
    avoid name clashes of names with names defined by subclasses), there
    is limited support for such a mechanism, called name mangling. Any
    identifier of the form __spam (at least two leading underscores, at
    most one trailing underscore) is textually replaced with
    _classname__spam, where classname is the current class name with leading underscore(s) stripped.

    In the parent-class definition, the attribute is defined as self.__database and Python “mangles” the name (to self._ClassName__attributename) so that any subclasses do not overwrite with their own assignment to their own self.__database attribute.

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

Sidebar

Related Questions

I use flask with flask-peewee and wtfpeewee. So, I have models like that: class
I have this to SQLAlchemy(using the Flask SqlAlchemy) objects defined: class User(db.Model): id =
I have an application that will use flask and mongodb; I will probably host
I use WTForms with Flask via the Flask.WTF extension. This question isn't Flask-specific, though.
In a flask application I wrote, I make use of an external library which
While programming under eclipse+PyDev and using Flask framework, I noticed that the auto-organizing imports
I am working on a Flask extension that adds CouchDB support to Flask. To
this is my Flask-SQLAlchemy Declarative code: from sqlalchemy.ext.associationproxy import association_proxy from my_flask_project import db
I am trying to use Elixir with Flask. Reason being using SQL Alchemy directly
I see that we can try Flask (the python micro framework from the browser,

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.