Skip to content
Advertisement

In which Python module is the input() function?

I’m making a module which is meant to convert an integer parameter into a roman numeral string and am trying to find out where the input() function is ’cause I’d like to be able to save the roman numeral product to a variable in a manner similar to the one in the input() function, that is:

>>> foo = romannum (32)
>>> print (foo)
"XXXII"

Advertisement

Answer

It’s in the builtins module.

>>> import builtins
>>> builtins.input is input
True
>>> help(input)
Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.

    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.

    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.

In Python 2, it was called __builtin__. But note that Python 3’s input() is like Python 2’s raw_input().


If you want to implement your own custom input function, you can read from sys.stdin just like a file.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement