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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:58:27+00:00 2026-06-07T05:58:27+00:00

Suppose we have the following code: class A: var = 0 a = A()

  • 0

Suppose we have the following code:

class A:
    var = 0
a = A()

I do understand that a.var and A.var are different variables, and I think I understand why this thing happens. I thought it was just a side effect of python’s data model, since why would someone want to modify a class variable in an instance?

However, today I came across a strange example of such a usage: it is in google app engine db.Model reference. Google app engine datastore assumes we inherit db.Model class and introduce keys as class variables:

class Story(db.Model):
    title = db.StringProperty()
    body = db.TextProperty()
    created = db.DateTimeProperty(auto_now_add=True)
s = Story(title="The Three Little Pigs")

I don’t understand why do they expect me to do like that? Why not introduce a constructor and use only instance variables?

  • 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-07T05:58:28+00:00Added an answer on June 7, 2026 at 5:58 am

    The db.Model class is a ‘Model’ style class in classic Model View Controller design pattern.
    Each of the assignments in there are actually setting up columns in the database, while also giving an easy to use interface for you to program with. This is why

    title="The Three Little Pigs"
    

    will update the object as well as the column in the database.

    There is a constructor (no doubt in db.Model) that handles this pass-off logic, and it will take a keyword args list and digest it to create this relational model.

    This is why the variables are setup the way they are, so that relation is maintained.

    Edit: Let me describe that better. A normal class just sets up the blue print for an object. It has instance variables and class variables. Because of the inheritence to db.Model, this is actually doing a third thing: Setting up column definitions in a database. In order to do this third task it is making EXTENSIVE behinds the scenes changes to things like attribute setting and getting. Pretty much once you inherit from db.Model you aren’t really a class anymore, but a DB template. Long story short, this is a VERY specific edge case of the use of a class

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

Sidebar

Related Questions

Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Say suppose I have the following Java code. public class Example { public static
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends
Suppose we have following code defined in tester.py class Tester( object ): def method(
Suppose I have an application with the following code: public class Node { public
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require

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.