Roy Smith wrote: > Why not just: > > if x is None: > result = str(x) > else: > result = "" > > It's a couple more lines of code, but it's obvious what it means.
and if you're doing this a few times, putting it in a function is even better. def tostring(obj): if obj is None: return "" return str(obj) print tostring(key) print tostring(foo), tostring(bar) file.write(tostring(record[1])) this also makes it easier to tweak things once you realize that not everything should be passed through str(): def tostring(obj): if obj is None: return "" if isinstance(obj, basestring): return obj return str(obj) </F> -- http://mail.python.org/mailman/listinfo/python-list