Convert None to Empty String in Python

Mon, Oct 12, 2009

Tech Tips

If you need to check for and convert the “None” string when returning the value of an object, here is a quick and readable method in python:

myObj = None
print myObj or ''

This brought back a reference to a blurb in Dive Into Python regarding ternary operators, although at the time I didn’t think of using it this way.

Bookmark and Share

One Response to “Convert None to Empty String in Python”

  1. Laurie Carlin Says:

    This is great! Thanks for your article. I am just starting django and this will help a lot.