How do I make list global please?

cmfinlay at SPAMmagnet.com.au cmfinlay at SPAMmagnet.com.au
Sun Apr 30 05:42:59 EDT 2000


How do I make list global please?

I have a list which comprise of mags[0] and mags[1]
I want to pass and return it from a subroutine.
my code is (in two text files)


from inittest import InitTest
mags = [333]
mags.remove(333)
mags.append(0) # (Big) array of magnets
mags.append(1) # (Big) array of magnets
print mags[0]
print mags[1]
InitTest()
print mags[0]
print mags[1]

# file :inittest.py
def InitTest():
   global mags
   print "I am in the Sub"
   Print mags[0]
   Print mags[1]
   print "Leaving Sub"
   return

I get the error message
QUOTE
Traceback (innermost last):
  File "inittest1.py", line 1, in ?
    from inittest import InitTest
  File "inittest.py", line 5
    Print mags[0]
             ^
SyntaxError: invalid syntax
UNQUOTE

my code works when it is all in the main routine.

Please post here or reply to
cmfinlay at SPAMmagnet.com.au



More information about the Python-list mailing list