Skip to content

Instantly share code, notes, and snippets.

@alecperkins
Created February 2, 2012 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecperkins/1725637 to your computer and use it in GitHub Desktop.
Save alecperkins/1725637 to your computer and use it in GitHub Desktop.
Script usability functions
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