I am looping through table rows in a table, but the first 1 or 2 rows doesn\'t have the elements I am looking for (they are for table column headers etc.).
So after
Simplest and clearest, if you want your code "in line":
theimage = td[0].a.img if theimage is not None: use(theimage['src'])
Or, preferably, wrap the None check in a tiny function of your own, e.g.:
None
def getsrc(image): return None if image is None else image['src']
and use getsrc(td[0].a.img).
getsrc(td[0].a.img)