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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:15:36+00:00 2026-05-29T23:15:36+00:00

Please educate me on how to do this the right way, as I feel

  • 0

Please educate me on how to do this the right way, as I feel my current way is long-winded.

I know iterating over all entities in App Engine is not quite how it is designed to be used, but sometimes I want to gather statistics about my entities, for example how many users are female. In reality the criteria might be something more complicated, but in any case something that requires examining each entity.

Here is some pseudoish code on how I am iterating over entities:

def handle_count_female_users(cursor = None, counter = 0):
    q = User.all()
    if cursor:
        q.with_cursor(cursor)
    MAX_FETCH = 100
    users = q.fetch(MAX_FETCH)

    count_of_female_users = len(filter(lambda user:user.gender == 'female', users))
    total_count = counter + count_of_female_users

    if len(users) == MAX_FETCH:
        Task(
            url = "/count_female_users",
            params = {
                'counter' : str(total_count),
                'cursor' : q.cursor()
            }
        ).add()
    else:
        # Now finally have the result
        logging.info("We have %s female users in total." % total_count)

I have routing code that automatically maps GET /foo to be handled by handle_foo, something that I’ve found convenient. As you can see, even with that I have a lot of stuff supporting the looping, having almost nothing to do with what I actually want to accomplish.

What I would really want to do is something like:

tally_entities(
    entity_class = User,
    filter_criteria = lambda user:user.gender == 'female',
    result = lambda count:logging.info("We have %s female users in total" % count)
)

Any ideas how to get closer to this ideal, or is there some even better way?

  • 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-29T23:15:37+00:00Added an answer on May 29, 2026 at 11:15 pm

    Sounds like a good use case for mapreduce:
    http://code.google.com/p/appengine-mapreduce/wiki/GettingStartedInPython

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

Sidebar

Related Questions

Please educate me. Why does this compile: struct compiles { struct A; struct B
I am a newbie for WCF, so please educate me. I am trying to
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
I have set myself upon a journey to educate my coworkers (all have accepted
Please consider this Query: SELECT tesd.State_Code, tesd.City_Code, tesd.Row_ID, tesd.Qsno, tesd.Total_Period, tesd.Current_Period, tesd.Week, tesd.Block_No, tesd.Family_ID,
Please correct me if I am wrong. I am asking this question to clarify
Please help me on this, its really irritating may be because i am doing
please help me out for the below problem, i am trying since long time(3
Can someone please educate me on why the result is what it is, instead
Hopefully this question won't be too convoluted or vague. I know what I want

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.