| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -992,18 +992,47 @@ are always available. They are listed here in alphabetical order. | |
| .. function:: input() | ||
| input(prompt, /) | ||
|
|
||
| If the *prompt* argument is present, it is written to standard output without | ||
| a trailing newline. The function then reads a line from input, converts it | ||
| to a string (stripping a trailing newline), and returns that. When EOF is | ||
| read, :exc:`EOFError` is raised. Example:: | ||
| Prompt the user for input, and return the answer as a string. | ||
| For example:: | ||
|
|
||
| >>> s = input('--> ') # doctest: +SKIP | ||
| --> Monty Python's Flying Circus | ||
| >>> s = input('What is your favorite color? ') # doctest: +SKIP | ||
| What is your favorite color? Yellow | ||
| >>> s # doctest: +SKIP | ||
| "Monty Python's Flying Circus" | ||
| 'Yellow' | ||
|
|
||
| If the :mod:`readline` module was loaded, then :func:`input` will use it | ||
| to provide elaborate line editing and history features. | ||
| >>> command = input('--> ') # doctest: +SKIP | ||
| --> cut the green wire | ||
| >>> command # doctest: +SKIP | ||
| 'cut the green wire' | ||
|
|
||
| .. admonition:: CPython implementation detail | ||
|
|
||
| By default, if the *prompt* argument is present, it is written to | ||
| standard output without a trailing space or newline. | ||
| The function then reads a line from input, converts it | ||
| to a string (stripping a trailing newline), and returns that. | ||
| When EOF is read, :exc:`EOFError` is raised. | ||
|
|
||
| If this exact behavior is required, implement it explicitly instead | ||
| of calling :func:`!input`:: | ||
|
|
||
| print(prompt, end='', flush=True) | ||
| sys.stdin.readline().strip('\n') | ||
|
|
||
| If the standard output is not interactive, then standard error | ||
| will be used for the prompt instead. | ||
|
|
||
| If the :mod:`readline` module was loaded, then :func:`input` will instead | ||
| use it to provide elaborate line editing and history features. | ||
| The may be used to | ||
| provide similar functionality. | ||
|
Comment thread
Comment on lines
+1027
to
+1028
Copy link
Copy Markdown
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt looks like there is a word missing between The and may.
Sorry, something went wrong.
encukou and johnslavik reacted with thumbs up emoji
All reactions
|
||
|
|
||
| Systems that lack standard input/output streams, or have different ways | ||
| of asking the user, often set :mod:`builtins.input <builtins>`, | ||
| or the C pointer :c:data:`PyOS_ReadlineFunctionPointer`, to a | ||
| more appropriate function. | ||
| For example, a framework for desktop applications could override | ||
| ``input`` to display a dialog. | ||
|
|
||
| .. audit-event:: builtins.input prompt input | ||
|
|
||
| Expand All | @@ -1015,6 +1044,11 @@ are always available. They are listed here in alphabetical order. | |
| Raises an :ref:`auditing event <auditing>` ``builtins.input/result`` | ||
| with the result after successfully reading input. | ||
|
|
||
| .. tip:: | ||
|
|
||
| Including a trailing space in *prompt*, as in the examples above, | ||
| often makes the result more pleasing. | ||
|
|
||
|
|
||
| .. class:: int(number=0, /) | ||
| int(string, /, base=10) | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI thought input was providing me with this low-level behaviour!
How sure are you that the specification in these previous paragraphs is a CPython implementation detail and not the Python builtin spec?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.