annotate common/str.py @ 361:f45456cdfb87

Added common.misc.homedir()
author Joseph Turian <turian@iro.umontreal.ca>
date Wed, 02 Jul 2008 23:56:51 -0400
parents 9e73e6dc9823
children
rev   line source
357
2291a244a887 Added common.string
Joseph Turian <turian@iro.umontreal.ca>
parents: 355
diff changeset
1 def percent(a, b):
355
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
2 """
357
2291a244a887 Added common.string
Joseph Turian <turian@iro.umontreal.ca>
parents: 355
diff changeset
3 Return percentage string of a and b, e.g.:
2291a244a887 Added common.string
Joseph Turian <turian@iro.umontreal.ca>
parents: 355
diff changeset
4 "1 of 10 (10%)"
2291a244a887 Added common.string
Joseph Turian <turian@iro.umontreal.ca>
parents: 355
diff changeset
5 """
355
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
6 assert a <= b
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
7 assert a >= 0
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
8 assert b > 0
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
9 return "%s of %s (%.2f%%)" % (a, b, 100.*a/b)