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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:11:56+00:00 2026-05-15T04:11:56+00:00

I’m getting back to programming for Google App Engine and I’ve found, in old,

  • 0

I’m getting back to programming for Google App Engine and I’ve found, in old, unused code, instances in which I wrote constructors for models. It seems like a good idea, but there’s no mention of it online and I can’t test to see if it works. Here’s a contrived example, with no error-checking, etc.:

class Dog(db.Model):
    name = db.StringProperty(required=True)
    breeds = db.StringListProperty()
    age = db.IntegerProperty(default=0)

    def __init__(self, name, breed_list, **kwargs):
        db.Model.__init__(**kwargs)
        self.name = name
        self.breeds = breed_list.split()

rufus = Dog('Rufus', 'spaniel terrier labrador')
rufus.put()

The **kwargs are passed on to the Model constructor in case the model is constructed with a specified parent or key_name, or in case other properties (like age) are specified. This constructor differs from the default in that it requires that a name and breed_list be specified (although it can’t ensure that they’re strings), and it parses breed_list in a way that the default constructor could not.

Is this a legitimate form of instantiation, or should I just use functions or static/class methods? And if it works, why aren’t custom constructors used more often?

  • 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-15T04:11:57+00:00Added an answer on May 15, 2026 at 4:11 am

    In your example, why not use the default syntax instead of a custom constructor:

    rufus = Dog( name='Rufus', breeds=['spaniel','terrier','labrador'] )
    

    Your version makes it less clear semantically IMHO.

    As for overriding Model constructors, Google recommends against it (see for example: http://groups.google.com/group/google-appengine/browse_thread/thread/9a651f6f58875bfe/111b975da1b4b4db?lnk=gst&q=python+constructors#111b975da1b4b4db) and that’s why we don’t see it in Google’s code.
    I think it’s unfortunate because constructor overriding can be useful in some cases, like creating a temporary property.

    One problem I know of is with Expando, anything you define in the constructor gets auto-serialized in the protocol buffer.
    But for base Models I am not sure what are the risks, and I too would be happy to learn more.

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

Sidebar

Ask A Question

Stats

  • Questions 427k
  • Answers 427k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According to the answer in this question, you'll need to… May 15, 2026 at 12:50 pm
  • Editorial Team
    Editorial Team added an answer Your parameters @monday and @friday are wrong, these have to… May 15, 2026 at 12:50 pm
  • Editorial Team
    Editorial Team added an answer You can do what you want to do, but I… May 15, 2026 at 12:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.