Can this be done in one line? Something that looks like this data['x'] = (x if x else "") (except doesn't raise an exception)
Otherwise I often end up doing the following:
try: data['x'] = x
except: data['x'] = ""
or for multiple keys initializing with empty values: i.e.
data['x'], data['y'] = [], []
data['x'] = xraise an exception? You meanxmight not be set? Generally, you'd avoid that kind of situation.x = ''and be done with it.