I want to create a global array so that these functions fib() and shoot() can share it. Here is my code:
global f
f=[0]*1000
def fib(n):
f[0]=1 ## error here
f[1]=1
for i in xrange(2,n+1):
f[i]=f[i-1]+f[i-2]
def shoot(aliens):
...
place to use f[] here
fib(999)
print shoot(line)
however it shows an error.
Traceback (most recent call last):
File line 56, in <module>
fib(999)
line 42, in fib
f[0]=1
TypeError: 'file' object does not support item assignment
please help!
Edit: Comments below made me realise that I had "with open('somefile') as f" in another part of my code not shown here. I removed that, and now, it's working.
fwhich is a file.f