question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Input function leaves newline before prompt

See original GitHub issue

Description

The version of Spyder/IPython I’m using is as follows (this is the startup prompt in the console): Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] Type “copyright”, “credits” or “license” for more information.

IPython 6.1.0 – An enhanced Interactive Python.

More version info below.

The problem I’m having is that when I try to use the input function, the console within spyder – whether I use the existing or new console – will display a blank line above where the input prompt is. This problem does not occur when I use an external console to display output/take input.

Note: I have already left this, nearly identical, report with the people at spyder. This was their response : “Thanks for the detailed report. Not sure the reasons behind this exact behavior (its possible its unintentional or not easily avoidable), but in any case it isn’t an issue with Spyder’s code, but rather qtconsole (as I reproduced it in plain qtconsole running separate from Spyder, but not IPython running in a standard terminal). Therefore, you’ll want to submit an issue over there, and I’ll close this one. Best of luck!”

What steps will reproduce the problem?

  1. Open the version of spyder/IPython listed above
  2. Input code including an input function without any newline characters above it or in the prompt. The test code I used was:
def test():
    print(1)
    print(2)
    input('Number: ')
    print(4)

test()
  1. Run the code

What is the expected output? What do you see instead? I expect to see (if my input is 3): 1 2 Number: 3 4

What I see instead is: 1 2

Number: 3 4

Please provide any additional information below Please tell me if there is anything more you need to see.

Version and main components

  • Spyder Version: 3.2.4
  • Python Version: 3.6.3
  • Qt Versions: 5.6.2, PyQt5 5.6 on Windows

Dependencies

pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.4 (OK)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
ghostcommented, Aug 9, 2018

check this : https://docs.python.org/3/library/functions.html#input

It says : input([prompt]) If the prompt argument is present, it is written to standard output without a trailing newline.

In your case there is no prompt , hence the trailing newline !

1reaction
ccordoba12commented, Jun 28, 2021

I have a fix for this but I need to see how to integrate with Spyder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Possible to get user input without inserting a new line?
raw_input () will always echo the text entered by the user, including the trailing newline. That means whatever the user is typing will...
Read more >
How to always print the prompt on a new line & keep input
1 Answer. Save this answer. Show activity on this post. This works as expected if I paste 2 commands into the terminal (both...
Read more >
2.4. Writing Output Without the Newline - bash Cookbook [Book]
Solution. Using printf it's easy—just leave off the ending \n in your format string. With echo, use the -n option.
Read more >
Java scanner.nextLine() Method Call Gets Skipped Error ...
It happens when you group together a bunch of input prompts and one of the scanner.nextLine() method calls gets skipped – without any...
Read more >
Input and the scanf function
Instead, you will want scanf to read only the visible characters, skipping white space (including the newline) as it does for numeric data....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found