Q:

Python - Global array

I tried to do:
x = []
def func():
   for y in range(0,5):
       x.append(y)

def func2():
   for i in range(0, 5):
       print x[i]

And I get the error:

IndexError: list index out of range

How can I put the global x array?  And access in the func2 the value of the x array. 

A:

You will get that error if you call func2 before calling func
>>> x=[]
>>> func2()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in func2
IndexError: list index out of range
>>> func()
>>> func2()
0
1
2
3
4

A:

It doesn't matter if you declared func() sooner than func2()
What matter is that you should call func() before func2(), otherwise you will get the error, because your array is still empty. 
So this:
x = []
def func():
    for y in range(0,5):
        x.append(y)

def func2():
    for i in range(0, 5):
        print x[i]
func()
func2()

WORKS! 
But this:
x = []
def func():
    for y in range(0,5):
        x.append(y)

def func2():
    for i in range(0, 5):
        print x[i]
func2()
func()

DOES NOT!