开发者

Python command line UI

Hey guys/gals I'm writing a python script that fixes some duplicate issues on my database. I would like to display some progress status to the users, currently I just print it like this:

print "Merged " + str(idx) + " out of " + str(totalCount);

The problem is that it prints that in a new line for every record and that does not look so good :) I'd like to either always print the string above on the same line on the screen or use some smart widget that displays i开发者_开发问答t in some sort of progress bar.

I intent to run this on the command line, any suggestions will be much appreciated.


If you just want to constantly overwrite the same line, use '\r' and print foo, to act as a carriage return and a non-endline-printing print.

while doingStuff:
    msg = "\rMerged %s out of %s" % (idx, totalCount)
    print msg,

But if you're designing a fancier console app, you maybe should look into using curses (only for Unix though)


Check out fish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜