I am using BeautifulSoup to parse XML:
xml = """<person>
<first_name>Matt</first_name>
</person>"""
soup = BeautifulStoneSoup(xml)
first_name = soup.find('first_name').string
last_name = soup.find('last_name').string
But I have a problem when there is no last_name, because it chokes. Sometimes the feed has it, and sometimes it doesn't. How do I prevent it from choking?
I don't want to use try/except statements. I also do not want to use if/else statements. (Since it'll double the lines of the already-very-long code if I have those statements).
Is there any way to just return "None" if there is no "last_name"?