How to address a global variable in a function

Aahz aahz at pythoncraft.com
Thu Aug 13 14:12:07 EDT 2009


In article <82c2f2e7-ed3e-482b-9318-d5539a2a9da8 at y10g2000prg.googlegroups.com>,
n179911  <n179911 at gmail.com> wrote:
>
>I have a global variable
>
>// line 8
>tx  = 0
>
>and then I have this function (start in line 12):
>def handleTranslate(result):
>	print line
>	txStr, tyStr = result.group(1), result.group(2)
>	print txStr, tyStr
>
>	tx += int(txStr)
>	ty += int(tyStr)
>
>	return

BTW, you probably want to learn why global names are a bad idea, I don't
have time to explain that here (or point you at references).  Going
through some of the online tutorials should address this.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz



More information about the Python-list mailing list