Deprecate input()

Ian Bicking ianb at colorstudy.com
Mon Apr 15 14:58:11 EDT 2002


On Mon, 2002-04-15 at 06:35, Magnus Lie Hetland wrote:
> But (in the (very?) long run) I think that the name "input" should
> then be used for what is now raw_input. I know -- breakage, and all
> that... I just think it fairly odd to have *only* raw_input, since the
> "raw" qualification then becomes fairly meaningless.

Why not just make input into what it should be, a moderately-evaluating
raw_input... like:

def input(prompt=''):
    val = raw_input(prompt)
    for converter in [int, float, complex]:
        try:
            return converter(val)
        except ValueError:
            pass
    return val


Of course, it gets more complex if you allow lists, dictionaries, and
tuples... which you probably should.  But that's certainly doable while
still being safe.

  Ian







More information about the Python-list mailing list