Created
February 2, 2012 20:40
-
-
Save alecperkins/1725637 to your computer and use it in GitHub Desktop.
Script usability functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def yellow(*args): | |
some_string = ' '.join([str(arg) for arg in args]) | |
return '\033[93m%s\033[0m' % (some_string,) | |
def green(*args): | |
some_string = ' '.join([str(arg) for arg in args]) | |
return '\033[92m%s\033[0m' % (some_string,) | |
def red(*args): | |
some_string = ' '.join([str(arg) for arg in args]) | |
return '\033[91m%s\033[0m' % (some_string,) | |
def iprint(some_string): | |
""" | |
Inline print, to avoid newlines and spacing from print. | |
""" | |
sys.stdout.write(some_string) | |
sys.stdout.flush() | |
def piprint(count, total): | |
""" | |
Inline percentage print, eg `piprint(25, 100)` clears the line and writes `25.00%` | |
""" | |
iprint('\r%.2f%%' % (count / float(total) * 100,)) | |
def tdelta(start, end): | |
""" | |
Returns a string of the timedelta between the start and end. | |
""" | |
return str(timedelta(seconds=round(end-start))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment