global name is not defined - error - but for array

A

a

def fn():
for i in range(l)
global count
count= ....

how do i declare count to be global if it is an array

subsequently i should access or define count as an array

error:
global name 'count' is not defined


thanks
-a
 
F

Fredrik Lundh

a said:
def fn():
for i in range(l)
global count
count= ....

how do i declare count to be global if it is an array


a couple of notes:

1) global statements should be placed at the top of the function

2) objects don't appear out of nowhere; you need to initialize the "count"
list before you can assign stuff to it. this is what causes the exception; the
global statement has nothing to do with that.

3) it's called "list" on Python, not "array".

4) if you read the tutorial, you'll learn better ways to loop over lists, and
build new lists. see the chapters "An Informal Introduction to Python",
"More Control Flow Tools", and "Data Structures".

5) posting one copy of your question is enough; if you feel that you want
to try out different subject lines, do that for yourself, before posting your
message to the list.

6) this list isn't hosted by googlegroups, so cancelling a post in googlegroups
doesn't mean that other people won't see it. there's a world outside google
too, you know...

</F>
 
S

Steve Holden

a said:
def fn():
for i in range(l)
global count
count= ....

how do i declare count to be global if it is an array

subsequently i should access or define count as an array

error:
global name 'count' is not defined

The questions you are asking make it likely you would get better help on
the Python-tutor list ([email protected], if memory serves me
right). It would seem you are new not just to Python but also to
programming, and that list is specifically for those who might find a
little coaching helpful.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top