Python 对多个文件使用函数

Python 对多个文件使用函数,python,file,numpy,pyfits,Python,File,Numpy,Pyfits,我已经编写了一个函数,需要用于多个文件。当我将它用于一个文件时,它可以工作,但当我尝试将它用于更多文件时,我会出错。我已经附上了我的代码,有人能告诉我有什么问题吗 #! /usr/bin/env python #peice of code to find the information from a star catalog for the brightest star from each indiviual CCD import os, sys, glob, pyfits, numpy d

我已经编写了一个函数,需要用于多个文件。当我将它用于一个文件时,它可以工作,但当我尝试将它用于更多文件时,我会出错。我已经附上了我的代码,有人能告诉我有什么问题吗

#! /usr/bin/env python
#peice of code to find the information from a star catalog for the brightest star from each indiviual CCD

import os, sys, glob, pyfits, numpy

dr='/home/desar2.cosmology.illinois.edu+7443/DESFiles/desardata/OPS/red/20130321211637_20130106/red/DECam_00166306/catalogs/'

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= numpy.mean(g)
 a=[q,j,z,h]
 print a
 s0=''
 return res

#image=dr+'DECam_00166306_01_star_catalog.fits'
#s=meanarr(image)

for arg in (sys.argv):
 print arg
 s=meanarr(arg)

print '---done---' 

它应该只为每个输入文件打印一个包含四位数字的列表,但我认为最后四行有问题。

sys.argv的第一个元素始终是您运行的脚本,而不是图像。这可能是错误吗

你应该这样做

for arg in sys.argv[1:]:
    print arg
    s=meanarr(arg)

请使用与您的编程环境相关的标记,例如
python
pyfits
,而不要使用过于通用的标记,例如
file
function
。好的,下次我会这样做。
sys.argv
的第一个元素始终是您运行的脚本,而不是图像。这可能是错误吗?