I have a Django management command that does quite a bit of processing, so I have it outputting its progress as a percentage. I'd like to use a technique as described in the answers here or here. I'm aware from the Django docs that sys.stdout
needs to be replaced with self.stdout
when used inside a management command, but I'm still having no luck. It's python 2.7, so I can't give the end
kwarg to print
. Here's one of the things I've tried in handle
of the Command object:
i = 0
for thing in query:
self.stdout.write("\r%%%s" % (100 * float(i) / float(query.count()))
i += 1
I've tried several other techniques described in answers to similar questions, including using ANSI escape sequences. Is there something special about the way that Django management commands print output? How can I achieve the effect I'm looking for?