Kent: Thank you for the explanation. This is a subtlety of Python that has tripped me up before.
Barry > Date: Mon, 07 Nov 2005 16:26:39 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Namespace Problem > Cc: "'tutor@python.org'" <tutor@python.org> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > <<snip>> > > seq += 1 > > The above statement binds a value to the name 'seq'. If a name is bound > anywhere within a block, the compiler treats it as a local name and it > will not be looked up in the global namespace. When the struct.pack() line > is executed, seq is not bound in the local namespace and you get an error. > The solution is to include 'global seq' in do_stuff(); this tells the > compiler that seq should always be treated as a global name even though it > is bound in the current block. > > This a little bit subtle because you are using seq += 1. Still this is > binding a new value to seq and you need to declare it global. > > Kent > <<snip>> _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor