Global variables?
RiGGa
rigga at hasnomail.com
Fri Jun 25 12:24:01 EDT 2004
Russell Blau wrote:
> "RiGGa" <rigga at hasnomail.com> wrote in message
> news:9VECc.21042$NK4.3479907 at stones.force9.net...
>> Hi,
>>
>> I am having problems getting my script to recognize global variables and
>> each time I run the script I always get this warning:
>>
>> SyntaxWarning: name 'getdata' is assigned to before global declaration
>>
>> The structure of my script is below:
>>
>
===========================================================================
>> import urllib
>> import sys
>> global myvariable
>
> This is in the wrong place -- you need this in the function where you are
> referencing the global name (see below).
>
>> myvariable = 0
>>
>> class MyHTMLParser(HTMLParser):
>>
>> def handle_starttag(self, tag, attrs):
>>
>> 'Do some stuff here and reassign a value to myvariable'
>>
>>
>> def handle_data(self, data):
>
> global myvariable
>>
>> if myvariable == 1:
>> 'Do some more stuff here'
>
>
Thank you!!!
More information about the Python-list
mailing list