Global array in python

koranthala koranthala at
Tue Sep 29 09:43:45 CEST 2009

On Sep 29, 5:48 am, Rudolf <yellowblueyel... at> wrote:
> How can i declare a global array in python?

As others have mentioned, you do not have concept of declaration. But
if you are looking for creating a global variable, it is like any
other language. Declare the same in a module, outside any procedures
or classes.

But, please note that it is not completely global. You have to go
inside the modules namespace to get it.
So, it will be like

Module A:
l = []

Module B:
import A
A.l ==> This is the global variable you are looking for.

To explain it further, every variable lives in a namespace. The
namespace can be that of a module (which is the global thing you are
looking for, I guess), or a class/object or even a procedure.

There is also a global keyword etc if that is what you are looking
for. Check out python documentation for more details.


More information about the Python-list mailing list