I'm an experienced programmer, but just a beginner in Python, and would like some input on a small function that's working but which I'm not very happy with.
It's used to produce XML tags (strings). The content argument can be a string, a number etc., but if it's a datetime I have to format it properly. Also, if there is no content, the tag should not be rendered (return empty string).
def tag(tagName, content): if isinstance(content, datetime): content = content.strftime('%Y%m%d%H%M') else: content = str(content) if content: return "<" + tagName + ">" + content + "</" + tagName + ">" return ""
Please enlighten me!