Explorar el Código

added int_input_with_default

Fabian Peter Hammerle hace 9 años
padre
commit
a1700b82ce
Se han modificado 1 ficheros con 11 adiciones y 0 borrados
  1. 11 0
      ioex/__init__.py

+ 11 - 0
ioex/__init__.py

@@ -10,3 +10,14 @@ def raw_input_with_default(prompt, default):
         return raw_input(prompt)
     finally:
         readline.set_pre_input_hook(None)
+
+def int_input_with_default(prompt, default):
+    if default:
+        default = str(default)
+    else:
+        default = ''
+    s = raw_input_with_default(prompt, default).strip()
+    if s:
+        return int(s)
+    else:
+        return None