Builtin function input
does not support scan formatted. Also, its return value can only be string. Users should do extra parsing actions and type conversions to get what they want.
This module provides several wrappers of builtin input
. They can statisfy above requirements easily.
Python3.3 or later.
$ pip install tinp
or you can clone this repo directly.
$ git clone https://github.com/dokelung/tinp.git
Read input by format string:
>>> from tinp import finput
>>> finput(prompt='==> ', fstr='%d, %f, %s')
==> 88, 12.3, hello
(88, 12.3, 'hello')
Read input and split it into several values with specified type:
>>> from tinp import tinput
>>> tinput(prompt='please enter 5 integers: ', typ=int)
please enter 5 integers: 1 2 3 4 5
(1, 2, 3, 4, 5)
Read input and evaluate it:
>>> from tinp import einput
>>> einput(prompt='==> ', typ=float)
==> 2+2
4.0