5

Spyder inserts a blank line in the console output between every call of the input() function but I don't want that (i.e. I want the input() prompts to be on contiguous lines in the console instead of separated by a blank line). Is there a way to do that? I tried using input("foo", end="") thinking it may work like the print() function but that's not the case...

Code:

fname = input("Please enter your first name: ")
lname = input("Please enter your last name: ")
print("Pleased to meet you, " + str(fname) + " " + str(lname) + "!")

Output:

Please enter your first name: Jane

Please enter your last name: Doe
Pleased to meet you, Jane Doe!

Desired output:

Please enter your first name: Jane
Please enter your last name: Doe
Pleased to meet you, Jane Doe!

Edit:

As others have pointed out in the comments section, this issue is non-reproducible, even for me, except through the use of the IPython interface within the Spyder IDE. If anyone is running IPython outside of Spyder, please run the above code and let me know whether that produces the same output. I can reproduce the undesired output through Spyder's IPython interface but not through a Terminal session so this is something specific to either IPython or Spyder.

Georgy
  • 12,464
  • 7
  • 65
  • 73
paanvaannd
  • 191
  • 3
  • 11
  • Are you running your code from the Python shell? – Christian Dean Jun 21 '17 at 05:12
  • @paanvaannd Your issue is non-reproducible... – cs95 Jun 21 '17 at 05:56
  • @ChristianDean I am running it from within Spyder, a Python IDE. There is an IPython console within the interface and running the code from there produces the output I described. Perhaps this is simply an issue with how IPython handles `input()`? – paanvaannd Jun 21 '17 at 05:58
  • @Coldspeed I was just typing the response above to Christian but you may be interested in seeing that as well since it may be the reason it's not reproducible in your environment. Perhaps it's an IPython thing. If that's the case, this isn't an issue and I'll just close the question. Thanks for the help, though! – paanvaannd Jun 21 '17 at 05:59

3 Answers3

2

(Spyder developer here) This looks like a minor bug in our IPython console. Please report it here:

https://github.com/jupyter/qtconsole

Note: This console is not simply embedding a terminal IPython session in Spyder (that's why making comparisons to it make no sense at all).

Instead, it is a re-implementation of most of the terminal behavior but using a graphical toolkit (called Qt) and the Jupyter kernel/frontend architecture.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
1

Perhaps not exactly what you're after, but it should solve your problem.

Delete previous line in console with:

def delete_previous_line():
    CURSOR_UP_ONE = '\x1b[1A'
    ERASE_LINE = '\x1b[2K'
    print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)


fname = input("Please enter your first name: ")
delete_previous_line()
lname = input("Please enter your last name: ")
print("Pleased to meet you, " + str(fname) + " " + str(lname) + "!")

See remote last STDOUT.

If it doesn't work try

print(CURSOR_UP_ONE + ERASE_LINE)

instead of

print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)
ChickenFeet
  • 2,653
  • 22
  • 26
  • Both suggested function call iterations (the ones with and without the last CURSOR_UP_ONE) actually add _another_ blank line between the input prompts within IPython for me. Running from Terminal, I get the input prompt lines being deleted themselves using the initial suggested iteration of the function (which is neat... I might use that in some more programs to clean up the output). It seems to be a way that IPython handles `input()` so I'll keep this open for a bit longer just to confirm. Thanks for the extra info, though! :+) – paanvaannd Jun 21 '17 at 17:03
-1

No extra empty lines in Window Vista console.

Extra empty lines are inserted in Spyder when "execute in current console" is choosen.

These extra lines are NOT inserted if program is executed in "dedicated console". (Python 3.6, Spyder 3.2.3, IPython 5.3.0)

Spyder -> Run -> Configuration per file... -> Execute in dedicated console

(2017/10/16, 32-bit Anaconda on MS Windows Vista 32 bit.)

slawek
  • 1