Python raw_input messing up string concatenation

陌路散爱 提交于 2019-12-02 01:20:31

This must be a problem related to a a trailing \r... Try this:

'test1' + proj.rstrip() + 'test2'

Explanation:

Your concatenated string contains \r in the middle. When printed, the console does print the beginning as test1... but when it encounters the \r, it "carriage-returns" to the beginning of the line, and overwrites it with the rest.

Further reading about newlines

You're running under Windows, correct? The string you enter is terminated by a DOS line ending, so that ProjRegex consists of test1abc\rtest2. When printed, the \r moves the cursor to the beginning of the line, at which point test2 overwrites test1.

Could you verify if you've set the PYTHONUNBUFFERED environment variable? When set on Windows, you will definitely run into issues where raw_input returns the \r. You can read more about it here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!