python nullable数组访问成语?

时间:2019-02-25 23:21:14

标签: python python-3.x

我需要访问一些嵌套结构,例如

zip = data['customer']['primary_contact']['address']['zip']

在其中一些可能为空(无)的情况下,有没有比编写更方便的方法

zip = None
if(not(data['customer'] is None)):
    if(not(data['customer']['primary_contact'] is None)):
        if(not(data['customer']['primary_contact']['address'] is None)):
            zip = data['customer']['primary_contact']['address']['zip']

0 个答案:

没有答案