Library of input functions with type conversion
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
README.rst
setup.py
test_tinp.py
tinp.py

README.md

tinp

Build Status Coverage Status

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.

Requirements

Python3.3 or later.

Installation

$ pip install tinp

or you can clone this repo directly.

$ git clone https://github.com/dokelung/tinp.git

Examples

finput

Read input by format string:

>>> from tinp import finput
>>> finput(prompt='==> ', fstr='%d, %f, %s')
==> 88, 12.3, hello
(88, 12.3, 'hello')

tinput

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)

einput

Read input and evaluate it:

>>> from tinp import einput
>>> einput(prompt='==> ', typ=float)
==> 2+2
4.0