View Full Version : [Python] Print function result

07-08-2012, 12:06 PM
Whenever I use a function I would like to have my results formatted as:
"# Result: %s #" %functionoutput

my current solution is:

def output(text, type="result"):
types = {"result":0, "warning":1, "error":2};
if types[type] == 0:
print ('# Result: ' + text + " #");
elif types[type] == 1:
print ('# Warning: ' + text + " #");
elif types[type] == 2:
print ('# Error: ' + text + " #");

is there a more elegant way of doing this?

07-08-2012, 12:32 PM
If you want it like you request, why aren't you doing it like that..? I have absolutely no idea what you are doing this for or why you'd want to, but couldn't you just reduce the entire thing down to:
def output(text, type='result'):
print '# %s: %s #' % (type, text)..??

07-08-2012, 12:38 PM
Well I just presumed there is something in the documentation that standardizes all "result" output.

That is a good solution, didn't see that simple solution - I simply over-thought the whole thing

07-08-2012, 02:54 PM
Maybe these are useful too
pm.warning('this is bad')
pm.error('this is awful')


CGTalk Moderation
07-08-2012, 02:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.