On Mon, Nov 4, 2013 at 5:34 AM, Ulrich Goebel <m...@fam-goebel.de> wrote: > Hallo, > > from a SQLite database I get a value by SELECT s from... which normaly is a > string, but can be the NULL value, wich means it is not defined. To put the > value into a form (made by QT) I need a string representation. > > str(s) gives either the string itself (which is good) or "None" (which is > not so good) in the case of NULL. Instead of "None" I would prefer an empty > string "". How to get that? > > Possibly there is a build in function smart(s1, s2, s3,...) which returns > the first s which is a useable string, or even "" if there isn't any string > in the arguments? > > Thanks for help > Ulrich > > > -- > Ulrich Goebel > Paracelsusstr. 120, 53177 Bonn > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor
In python you can do this: >>> a = None >>> b = a or "" >>> b '' >>> a = "text here" >>> b = a or "" >>> b 'text here' >>> If a is None (false in python), it will check the value after or and return that. If a is a string (hence true in python) it will return the string -- Joel Goldstick http://joelgoldstick.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor