Thanks for the heads up on logging.
I tried the logging but don't know if I did it right. For the first
logging part in the code, I put:
logging.info('Wrote answer, key is: %s', str(answer.key()))
and it gave me this in the browser:
AttributeError: 'Key' object has no attribute 'key'
I tried replacing key with ans but that gave the same error type.
When I just put:
logging.info('Wrote answer, key is: %s', str(answer))
the log file comes with this:
Wrote answer, key is agxkZXZ-bnVtZ3Vlc3NyDAsSBkFuc3dlchhUDA
Am I doing something wrong or does this info mean anything? I honestly
don't know what to make of it or what to change to get the random
number in/out.. I feel like I am following what the docs say though.
On Aug 17, 10:19 pm, Robert Kluin <[email protected]> wrote:
> Hi,
> You should check out the Python logging package, it is super handy.
> Add some logging calls to your code so you can see what is happening.
> For example:
>
> import logging
>
> def post(self):
> stguess = self.request.get('guess')
> if stguess == 'new':
> answer = Answer(ans = (random.randint(1, 100))).put()
> logging.info('Wrote answer, key is: %s', str(answer.key()))
> number = Answer.all().get()
> if number is not None:
> logging.info('Got answer, value is: %d', number.ans)
> answer = number.ans
> else:
> logging.info('Oh No! Got no answer!')
> answer = None
> else:
> logging.info('Doing nothing.')
>
> Robert
>
>
>
>
>
>
>
> On Wed, Aug 17, 2011 at 17:33, Matt <[email protected]> wrote:
> > I am trying to pull an integer from the datastore but I keep getting
> > None back. I store the integers here-
>
> > class Answer(db.Model):
> > ans = db.IntegerProperty()
>
> > As a test I did this -
>
> > def post(self):
>
> > stguess = self.request.get('guess')
> > if stguess == 'new':
> > answer = Answer(ans = (random.randint(1, 100))).put()
> > number = Answer.all().get()
> > if number is not None:
> > answer = number.ans
> > else:
> > answer = None
> > msg = str(answer)
>
> > So what that does is take user input from the user and if they entered
> > 'new' follow the if path. ans equals a random integer between 1 and
> > 100. Put it in Answer. Then immediately after, pull the first integer
> > from Answer. If it is not None assign the variable answer to the
> > result, else assign it to None. msg is displayed on screen. Instead of
> > a random number which I am expecting to be displayed, None is
> > displayed instead.
>
> > I also tried using count to see how many items were actually in the
> > database and the count was more than 0.
>
> > Is there anything wrong with how I am putting or retrieving from the
> > datastore? How can I change this so I get the random number into the
> > answer variable, not None?
>
> > Thanks for any help
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/google-appengine?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.