Преглед изворни кода

added int_input_with_default

Fabian Peter Hammerle пре 9 година
родитељ
комит
a1700b82ce
1 измењених фајлова са 11 додато и 0 уклоњено
  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