有没有办法忽略通过 raw_input 输入的数据中的换行符?我正在尝试使用 raw_input 输入从电子表格复制和粘贴的字符串列表。问题是换行符似乎会导致数据过早输入。无论如何,所有空格都会被删除,因此在输入数据时删除换行符将是一个额外的好处。该数据需要通过终端提示直接输入,而不是从文件中读取。
这是我到目前为止所做的:
names = raw_input('Shoot me some names partner: ')
print 'What do you want to do?'
print '1 - format names for program 1'
print '2 - format names for program 2'
first_act = raw_input('Enter choice: ')
print names
print first_act
现在,当我运行它并输入我放入谷歌文档电子表格中的虚拟名称进行测试时,只要我按下 shift+ctl+v,而不按下回车,我就会得到:
seth@linux-1337:~> python pythonproj/names.py
Shoot me some names partner: abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnopWhat do you want to do?
1 - format names for program 1
2 - format names for program 2
Enter choice: abcd,efg,hijkl,mnop
abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
If 'abcd,efg,hijkl,mnop' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
If 'abcd,efg,hijkl,mnop' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
If 'abcd,efg,hijkl,mnop' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
If 'abcd,efg,hijkl,mnop' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
If 'abcd,efg,hijkl,mnop' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf abcd,efg,hijkl,mnop
seth@linux-1337:~> abcd,efg,hijkl,mnop
我对 python 很陌生,而且我不是迄今为止最有经验的程序员。这是python 2.7。