Why Is There A Blank Line Between My Print And Raw_input Lines?
Solution 1:
As much as I'm not a Canopy fan I think that the conclusion that its a Canopy bug is unfair. I think its an issue when using raw_input involving the inclusion of IPython within an IDE. Why?
My test code was:
print"Error if there is an extra line before 1"print"Error if there is an extra line before 2"
guess = raw_input("This line should follow directly")
I tested the code in a number of environments (Python 2.7):
- Canopy: fail
- Spyder with IPython window: fail
- IPython in Jupyter QtConsole: fail
- ipython: good
- python: good
- Spyder using a Python console.
So, I conclude that IPython, in a non-terminal environment is generating an extra linefeed for some reason before a raw_input(). Note that this still applies with Python 3.5 using input.
Solution 2:
EDIT The conclusion from the discussion in the comments is it's a bug in Canopy IDE.
The code you're showing us is not the code you're running.
Your output is this:
Available Letters:abcdefghijklmnopqrstuwxyz.
Which is supposed to be printed by this (note the dot added on the end):
print"Available Letters: " + getAvailableLetters(lettersGuessed) + "."
But getAvailableLetters
also adds a dot on the end of its return value.
defgetAvailableLetters(lettersGuessed):
import string
str = string.ascii_lowercase
for char in lettersGuessed:
if char instr:
str = str.replace(char, "")
returnstr + '.'
So the output should be this:
Available Letters:abcdefghijklmnopqrstuwxyz..
My conclusion is the code you're showing us and the code you're running cannot be the same. I would suggest pasting the code somewhere for us to examine fully. Github Gist will do.
Post a Comment for "Why Is There A Blank Line Between My Print And Raw_input Lines?"