[Uludag-commits] r15331 - trunk/comar/mudur/bin

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
6 Eyl 2007 Per 09:41:12 EEST


Author: bahadir.kandemir
Date: Thu Sep  6 09:41:12 2007
New Revision: 15331

Modified:
   trunk/comar/mudur/bin/network.py
Log:
Error tolerant string to integer conversion

Modified: trunk/comar/mudur/bin/network.py
=================================================================
--- trunk/comar/mudur/bin/network.py	(original)
+++ trunk/comar/mudur/bin/network.py	Thu Sep  6 09:41:12 2007
@@ -21,12 +21,24 @@
 _ = __trans.ugettext
 
 
+def str2int(input):
+    """ Error tolerant string to integer conversion function. """
+    nums = []
+    for char in input:
+        if not char.isdigit():
+            break
+        nums.append(char)
+    if nums:
+        return int("".join(nums))
+    else:
+        return 0
+
 def input_number(max_no):
     """ Checks limits of read input from command line -any excess will cause warning- """
-    input = int(raw_input('-> '))
+    input = str2int(raw_input('-> '))
     while ( input >= max_no or input <= 0 ) :
         print _("Limit excess, please enter a valid number: ( interval: 0 < entry < %s )") % max_no
-        input = int(raw_input('-> '))
+        input = str2int(raw_input('-> '))
     return input
 
 def collect(c):


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi