我编写了一个函数,它从外部文件中读取数据并生成列表。该程序运行良好,我有一个读入的每个文件的数字列表。但我是 python 新手,正在努力将其保存到文件中,这是我的程序和 savefile 行:
def meanarr(image, res=None):
"costruct code which runs over a single ccd to get the means"
a=pyfits.getdata(image).MAG_AUTO
q=numpy.mean(a)
s=pyfits.getdata(image).X2WIN_IMAGE
j=numpy.mean(s)
f=pyfits.getdata(image).Y2WIN_IMAGE
z=numpy.mean(f)
g=pyfits.getdata(image).XYWIN_IMAGE
h= abs(numpy.mean(g))
a=[q,j,z,h]
print a
return res
for arg in sys.argv[1:5]:
#print arg
s = meanarr(arg) #meanarr is my function
datafile = open('writetest.txt', 'w')
for l in meanarr(arg):
datafile.write(l)
datafile.close()
但我收到一个错误TypeError: 'NoneType' object is not iterable
,我不确定为什么,因为我的函数确实会产生数据。有人可以帮忙吗?