On Wed, Jun 10, 2009 at 6:50 AM, dasacc22 <[email protected]> wrote:
>
> > Also, I seem to be missing the point of
> > "bullets = []".
>
> the way you were using the global bullets list was confusing to me.
> Basically i couldn't tell if you were declaring the global first
> somewhere. Heres an example, you can pull up a python interpretor
>
> class A(object):
>    global s
>
>    def greet(self):
>        print s
>
>    def reset(self):
>        s = 'reset'
>
>
> >>> a = A()
> >>> a.greet()
> Name Error: global name 's' not defined
> ' ok so now lets set it in globals '
> >>> s = 'Bonjour Mary!'
> >>> a.greet()
> Bonjour Mary!
> ' ok so lets see if our reset function works '
> >>> a.reset()
> >>> a.greet()
> Bonjour Mary!
>
> Nope, this is b/c theirs some weird clashing going on that i dont
> fully understand. It can be alleviated by declaring global s in every
> function like so:
>

You don't need to declare s as global in every function that uses s, only in
the functions that set s.
Using a variable 's' always uses the 'closest' definition of s, which will
be the global definition unless a local variable also named 's' has been
set.

When you go to set s, assignment will create a local variable, unless s has
been declared as global within this function body.

-- 
Tristam MacDonald
http://swiftcoder.wordpress.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" 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/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to