-2

这是我试图在 python 中运行的程序的一部分,但它给了我一个KeyError

def xi_group_prep(infile=os.environ ['GAMA_DATA'] + '/groups/G3Cv04/G3CFoFGroup194v04.dat'

编码:

def xi_mass_samples(infile='/export/scratch/loveday/gama/stellarMasses/StellarMassesPlus.fits',
                    ranfile='/export/scratch/loveday/gama/mask/mass_randoms_194.dat',):
    """
    Create mass sub-samples for xi(s).
    """
    Mlimits = (5, 9.5, 10, 10.5, 11, 11.5, 15)
    for i in range(len(Mlimits)-1):
        Mlo = Mlimits[i]
        Mhi = Mlimits[i+1]
        galout = 'gal_lgm' + str(Mlo) + '_' + str(Mhi) + '.dat'
        ranout = 'ran_lgm' + str(Mlo) + '_' + str(Mhi) + '.dat'
        xi_select(infile,
                  ranfile=ranfile,
                  galout=galout, ranout=ranout,
                  zrange=(0.002, 0.5), nz=50, 
                  appMin=14, appMax=19.4, lgmMin=Mlo, lgmMax=Mhi)

def xi_group_prep(infile=os.environ ['GAMA_DATA'] + '/groups/G3Cv04/G3CFoFGroup194v04.dat',
                  ranfile='/export/scratch/loveday/gama/mask/mass_randoms_194.dat',
                  galout='group.dat', ranout = 'ran_group.dat',
                  zrange=(0.002, 0.5), lgmMin=5, lgmMax=15,
                  appMin=14, appMax=19.4, absMin=-30, absMax=12):
4

1 回答 1

1

正如错误消息可能显示的那样,os.environ没有密钥'GAMA_DATA',因此KeyError在尝试访问它时会给出一个。请注意,默认参数是在函数定义时评估的,因此此时必须存在此键。

于 2012-06-20T13:29:47.653 回答