It's probably a scoping problem. When using a variable name that's the same
with the one defined outside, you can only use it as reference to the value
outside, or as a new local variable, but not both. And you declare that a
variable is local to the function by having an assignment operation on that
variable inside the function. And once it's local, it'll always be local,
even for statements before the first assignment operation.

For example:
def test():
    a = 1
    def f():
            b = a # the variable 'a' is supposed to be a reference outside
            a = 0 # the variable 'a' becomes local, even in the above
statement
            return b
    return f
f = test()
f() # UnboundLocalError raised

So it's better to just pass the needed values as arguments to the function
so that you won't have this kind of problem.

On Sun, May 17, 2009 at 10:34 AM, astrid.thuec...@googlemail.com <
astrid.thuec...@googlemail.com> wrote:

>
> I encounter a very strange error which wasn't here before and I
> already wonder if it is due to some kind of indendation problem.
>
> Anyway. The transaction accesses variables that were defined in the
> sourcecode before the transaction:
>
>        some variables
>
>        def txn():
>            if (...):
>                ....
>            else:
>               ....
>        db.run_in_transaction(txn)
>
>
> in the if and else parts it sometimes complains that the variables I
> clearly defined before the transaction method were referenced before
> they were defined. It is even more confusing since some variables seem
> to be working in the if block but not in the else block and vice
> versa.
>
> Any clue what I am missing?
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to