[Python-checkins] CVS: distutils/distutils util.py,1.46,1.47

Greg Ward python-dev@python.org
Sun, 24 Sep 2000 18:25:16 -0700


Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2664

Modified Files:
	util.py 
Log Message:
Added 'strtobool()' function: convert strings like "yes", "1", 
"no", "0", etc. to true/false.

Index: util.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/util.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -r1.46 -r1.47
*** util.py	2000/09/22 01:05:43	1.46
--- util.py	2000/09/25 01:25:06	1.47
***************
*** 274,275 ****
--- 274,290 ----
  
  # execute()
+ 
+ 
+ def strtobool (val):
+     """Convert a string representation of truth to true (1) or false (0).
+     True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
+     are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
+     'val' is anything else.
+     """
+     val = string.lower(val)
+     if val in ('y', 'yes', 't', 'true', 'on', '1'):
+         return 1
+     elif val in ('n', 'no', 'f', 'false', 'off', '0'):
+         return 0
+     else:
+         raise ValueError, "invalid truth value %s" % `val`