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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:30:45+00:00 2026-05-13T09:30:45+00:00

I want determine the type of an attribute in a class. I am using

  • 0

I want determine the type of an attribute in a class. I am using setattr to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling setattr.

How do you do this in python?

EDIT 1-
Some additional information based on the answers so far:

I only know the name of the property that I want the type for, here is some code:

def populate_object_properties(values_as_strings, 
                               object_to_populate, 
                               properties_to_populate):
    for k in properties_to_populate:        
        value = values_as_strings.get(k)
        if value:
            setattr(object_to_populate, k, value)
        else:
            setattr(object_to_populate, k, None)

I want to be able test that value is the right type before I call setattr.

Edit 2- The reason why I need to validate the type, is that I’m using Google AppEngine’s db.Model as the base type for the object_to_populate, and it doesn’t like when a put a string into an int type. I was trying to keep the question as simple as possible, but maybe that piece of information makes a difference in how someone would answer.(?)

  • 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-13T09:30:45+00:00Added an answer on May 13, 2026 at 9:30 am

    In AppEngine, each model has a properties() class method, which returns the dict of properties you declared in your model. You can use it to check the types your model expects for each attribute:

    def populate_object_properties(values_as_strings, 
                                   object_to_populate, 
                                   properties_to_populate):
        model_properties = object_to_populate.properties()
        for k in properties_to_populate:        
            value = values_as_strings.get(k)
            model_property = model_properties.get(k)
            if value:
                if isinstance(model_property, StringProperty):
                    setattr(object_to_populate, k, str(value))
                elif isinstance(model_property, IntegerProperty):
                    setattr(object_to_populate, k, int(value))
            else:
                setattr(object_to_populate, k, None)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class C(Of T). I want to determine if some given value
I want to distinctly determine if the type that I have is of custom
I want to determine whether MyBindingSource.DataSource is assigned to the designer set Type ,
I want to determine the browser type in code-behind file using C# on ASP.NET
How can I determine the type of file system that is used by a
I want to determine if a generic object type (T) method type parameter is
I want to determine the scroll of the users. I'm using jQuery.. And jquery
I want to determine the following QoS Attribute of my service: Response Time Reliability
Let's say I have a Type called type . I want to determine if
MSDN is rather vague regarding this attribute. The custom data string can be set

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.