我可以在def __init__中设置未传递到def __init__的变量吗?

时间:2019-01-31 19:24:27

标签: python

可以在“ def init”中设置未传递给函数的属性吗?像下面的这段代码一样,仅传递env。但是我希望类中的函数了解local_gdb和reference_data。

类规格:

def __init__(self, env):
    self.env = env
    local_gdb = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Clip.gdb")
    self.local_gdb = local_gdb
    self.reference_data = {
        'moa_centerline': {'sde': 'MOAADM.Addressing_DBO_STREETS\MOAADM.streets',
                           'gdb': os.path.join(local_gdb, 'MOA_Streets')},
        'moa_address': {'sde': 'MOAADM.ADDRESS_POINT',
                        'gdb': os.path.join(local_gdb, 'MOA_Address')},
        'kpb_address': {'sde': "KPBADM.PhysicalAddress",
                        'gdb': os.path.join(local_gdb, "KPB_Address")},
    }

1 个答案:

答案 0 :(得分:0)

我将一流的规范重构为:

local_gdb = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Clip.gdb")
reference_data = {
    'moa_centerline': {'sde': 'MOAADM.Addressing_DBO_STREETS\MOAADM.streets',
                       'gdb': os.path.join(local_gdb, 'MOA_Streets')},
    'moa_address': {'sde': 'MOAADM.ADDRESS_POINT',
                    'gdb': os.path.join(local_gdb, 'MOA_Address')},
    'kpb_address': {'sde': "KPBADM.PhysicalAddress",
                    'gdb': os.path.join(local_gdb, "KPB_Address")},
}

def __init__(self, env):
    self.env = env