我需要访问一些嵌套结构,例如
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']