How to ingore "AttributeError: exception
Ganesh Pal
ganesh1pal at gmail.com
Fri Sep 22 04:55:12 EDT 2017
I have two possible values for Z_block in the block code i.e
disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0]
def get_block():
''' Get Z block ''
if block.data.data.di_data.data[0][0] is not None:
Z_block = block.data.data.di_data.data[0][0]
else:
Z_block = disk_object.data.data.di_data[0]
if not Z_block:
return False
return Z_block
I have a problem with if and else satement i.e if IF codition fails the
code would exit with "AttributeError: 'list' object has no attribute
'data' " error
Any suggestion on how this can be handled better , Will ignoring the
exceptions in try -except with pass be good or are there easier ways ) ,
try:
Z_block = block.data.data.di_data.data[0][0]except AttributeError as e:
pass
I am a Linux user on Python 2.7
Regards,
Ganesh
More information about the Python-list
mailing list