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:
JavaScript
x
4
1
>>> foo = romannum (32)
2
>>> print (foo)
3
"XXXII"
4
Advertisement
Answer
It’s in the builtins
module.
JavaScript
1
15
15
1
>>> import builtins
2
>>> builtins.input is input
3
True
4
>>> help(input)
5
Help on built-in function input in module builtins:
6
7
input(prompt=None, /)
8
Read a string from standard input. The trailing newline is stripped.
9
10
The prompt string, if given, is printed to standard output without a
11
trailing newline before reading input.
12
13
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
14
On *nix systems, readline is used if available.
15
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.