DocWiki DocWiki - 1 year ago 94
Python Question

Python: Store a num in Google App Engine

I am using Google App Engine Python.

I would like to store a simple variable number somewhere, so I can add, deduct and use this number.


Next time I use this examplenum, it wil become 6.

I know I can build a
and add an
varible. But I guess that would be too much hassle because I only need one simple number not a model.

I have also read this question Simplest way to store a value in Google App Engine Python?, the
solution is not good for me. I want the number to stay forever not just temporary in the

Thanks a lot.

Answer Source

All the answers to the question you linked are relevent to you. If you want persistance you will have to create a model. Look at using get_or_insert to fetch/initialize an entity and give your entity a key_name so that you can keep fetching it easily whenever you need to store your values.

class MyAppData(db.Model):
    my_number = db.IntegerProperty()

# fetch entity whenever you need to store your value
data = MyAppData.get_or_insert(key_name='mydata', my_number=1)

data.my_number += 1

You code does look suspiciously like a counter, and you might want to look at the sharding countering article and the problems that it solves in case they are relevent.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download